|
|
|
@ -27,17 +27,13 @@ export default {
|
|
|
|
},
|
|
|
|
},
|
|
|
|
data() {
|
|
|
|
data() {
|
|
|
|
return {
|
|
|
|
return {
|
|
|
|
// activeIndex: this.current, // 改用computed计算属性
|
|
|
|
targetScrollId: `tab-${this.current}`, // 核心变量:控制scroll-into-view的目标id
|
|
|
|
// targetScrollId: `tab-${this.current}`, // 核心变量:控制scroll-into-view的目标id(改用computed计算属性)
|
|
|
|
|
|
|
|
};
|
|
|
|
};
|
|
|
|
},
|
|
|
|
},
|
|
|
|
computed: {
|
|
|
|
computed: {
|
|
|
|
activeIndex() {
|
|
|
|
activeIndex() {
|
|
|
|
return this.current;
|
|
|
|
return this.current;
|
|
|
|
},
|
|
|
|
},
|
|
|
|
targetScrollId() {
|
|
|
|
|
|
|
|
return `tab-${this.current}`;
|
|
|
|
|
|
|
|
},
|
|
|
|
|
|
|
|
},
|
|
|
|
},
|
|
|
|
methods: {
|
|
|
|
methods: {
|
|
|
|
// 点击tab切换(核心:通过变量赋值控制滚动)
|
|
|
|
// 点击tab切换(核心:通过变量赋值控制滚动)
|
|
|
|
@ -45,7 +41,7 @@ export default {
|
|
|
|
if (this.activeIndex === index) return;
|
|
|
|
if (this.activeIndex === index) return;
|
|
|
|
this.activeIndex = index;
|
|
|
|
this.activeIndex = index;
|
|
|
|
this.$emit("change", index);
|
|
|
|
this.$emit("change", index);
|
|
|
|
|
|
|
|
console.log();
|
|
|
|
// 计算要滚动到的目标id,让相邻tab显示到可视区
|
|
|
|
// 计算要滚动到的目标id,让相邻tab显示到可视区
|
|
|
|
this.calcTargetScrollId(index);
|
|
|
|
this.calcTargetScrollId(index);
|
|
|
|
},
|
|
|
|
},
|
|
|
|
|