第一种写法为什么会报错
写法一 报错
export class Swip1{
methods:{
swipeHandler: function(params) { <- 这个地方提示有错
if(-1 < temp && temp< this.magjorCategoryList.majorCategory.length){
this.setSelect = temp;
console.log(this.magjorCategoryList.majorCategory[temp])
this.changeSelect(temp,this.magjorCategoryList.majorCategory[temp])
this.$bus.$emit("activeTabToCenter", document.getElementById('label' + temp));
}
}
}
}
写法二 没问题
export let Swip = {
methods: {
swipeHandler: function (temp) {
if(-1 < temp && temp< this.magjorCategoryList.majorCategory.length){
this.setSelect = temp;
console.log(this.magjorCategoryList.majorCategory[temp])
this.changeSelect(temp,this.magjorCategoryList.majorCategory[temp])
this.$bus.$emit("activeTabToCenter", document.getElementById('label' + temp));
}
}
}
}
建议看一下 阮一峰老师的 Class 的基本语法 - ECMAScript 6入门。
类的属性和方法并不是你这样写的。
如果你有想要用混入可以这样写
然后再在你需要引入混入的组件里面这样引入就行了
同时
Vue
的文档也可以好好看看的,特别是在你需要用到的时候。关于混入的部分在这里 👉 混入 — Vue.js