tab.vue:
<view v-for="(item, index) in list" :key="index" class="tab-scroll_item" :class="{active:activeIndex === index}" @click="clickTab(item, index)">{{item.name}}</view>
export default {
name:"tab",
props:{
list: {
type: Array,
default(){
return[]
}
},
tabIndex: {
type:Number,
default: 0
}
},
//监听 data, props 值的变化
watch: {
tabIndex(newVal, oldVal){
// tabIndex(newVal){
console.log(newVal,oldVal);
this.activeIndex = newVal;
}
},
methods:{
clickTab(item, index){
// console.log(item, index);
this.activeIndex = index ;
this.$emit('tab',{
data:item,
index:index
})
}
},
data(){
return {
activeIndex: 0
};
}
index.vue:
<tab :list="tabList" :tabIndex="tabIndex" @tab="tab"></tab>
methods: {
change(current){
this.tabIndex = current;
console.log('当前swiper: ', current);
},
tab(data,index){
console.log(data,index);
this.activeIndex = index
}
打印出来:
全部包裹在里面了, index没有拆分出来
{
"data": {
"_id": "66d59bbeb9fb236ac3ff03a5",
"name": "持仓",
"user": []
},
"index": 2
}