vue学习笔记--我遇到的问题
2018-07-06 本文已影响15人
迷路de鸽子啊
在vue中使用sass?
安装依赖 cnpm install --save-dev node-sass sass-loader
vue中实现tab切换
<template>
<div>
<nav>
<div class="nav-list" :class="{active:index==num}" v-for="(item ,index) in navList" @click="tab(index)">{{item}}</div>
</nav>
<div class="tab-main">
<div class="tab-item" v-for="item in contList" v-show="index==num">{{item}}</div>
</div>
</div>
</template>
<script>
export default {
data () {
return {
num:0;
}
},
methods:{
tab(index){
this.num = index;
}
}
}
</script>
轮播图
使用vue-awesome-swiper官网链接
1.下载插件
npm install vue-awesome-swiper --save
2.全局注册main.js
var VueAwesomeSwiper = require('vue-awesome-swiper')
Vue.use(VueAwesomeSwiper)
3.模板中使用
<template>
<swiper :options="swiperOption" ref="mySwiper">
<!-- slides -->
<swiper-slide>I'm Slide 1</swiper-slide>
<swiper-slide>I'm Slide 2</swiper-slide>
<swiper-slide>I'm Slide 3</swiper-slide>
<swiper-slide>I'm Slide 4</swiper-slide>
<swiper-slide>I'm Slide 5</swiper-slide>
<swiper-slide>I'm Slide 6</swiper-slide>
<swiper-slide>I'm Slide 7</swiper-slide>
<!-- Optional controls -->
<div class="swiper-pagination" slot="pagination"></div>//
<div class="swiper-button-prev" slot="button-prev"></div>
<div class="swiper-button-next" slot="button-next"></div>
<div class="swiper-scrollbar" slot="scrollbar"></div>
</swiper>
</template>
<script>
import { swiper, swiperSlide } from 'vue-awesome-swiper'
// swiper options example:
export default {
name: 'carrousel',
components: {
swiper,
swiperSlide
},
data() {
return {
swiperOption: {//以下配置不懂的,可以去swiper官网看api,链接http://www.swiper.com.cn/api/
// notNextTick是一个组件自有属性,如果notNextTick设置为true,组件则不会通过NextTick来实例化swiper,也就意味着你可以在第一时间获取到swiper对象,<br> 假如你需要刚加载遍使用获取swiper对象来做什么事,那么这个属性一定要是true
notNextTick: true,
// swiper configs 所有的配置同swiper官方api配置
autoplay: 3000,
direction : 'vertical',
grabCursor : true,
setWrapperSize :true,
autoHeight: true,
pagination : '.swiper-pagination',
paginationClickable :true,
prevButton:'.swiper-button-prev',//上一张
nextButton:'.swiper-button-next',//下一张
scrollbar:'.swiper-scrollbar',//滚动条
mousewheelControl : true,
observeParents:true,
// 如果自行设计了插件,那么插件的一些配置相关参数,也应该出现在这个对象中,如下debugger
debugger: true,
}
}
},
}
子组件向父组件传值
// 子组件 src/components/search.vue
<template>
<input type="" @keyup="query" v-model="text">
</template>
<script>
export default {
methods:{
data () {
text:''
}
query () {
this.$emit('searchText',this.text);
}
}
}
</script>
//父组件
<template>
<search-box @searchText="search"></seach-box>
{{inputText}}
</template>
<script>
import SearchBox from "src/components/search"
export default {
components:{
SearchBox
},
methods:{
data () {
inputText:''
}
search (data) {
this.inputText = data;
}
}
}
</script>
实现如图所示的轮播nav
轮播图第一屏 轮播图第二屏<template>
<swiper>
<swiper-slide v-for="(page, index) of pages" :key="index">
<div
class="icon"
v-for="item of page"
:key="item.id"
>
<div class='icon-img'>
<img class='icon-img-content' :src='item.imgUrl' />
</div>
<p class="icon-desc">{{item.desc}}</p>
</div>
</swiper-slide>
</swiper>
</template>
<script>
export default {
computed:{
pages () {
let pages = [];
this.iconList.forEach((item, index) => {
let page = Math.floor(index / 8) {
if (!pages[page]) {
pages[page] = []
}
pages[page].push(item)
}
})
return pages
}
}
}
</script>
实现层级嵌套列表时,我们可以在组件中调用自身组件,
<template>
<div>
<div
class="item"
v-for="(item, index) of list"
:key="index"
>
<div class="item-title border-bottom">
<span class="item-title-icon"></span>
{{item.title}}
</div>
<div v-if="item.children" class="item-chilren">
<detail-list :list="item.children"></detail-list>
</div>
</div>
</div>
</template>