场景:在vue中使用es6语法的箭头函数无法正常的使用this下面的方法
原因:计算属性computed不应该使用箭头函数来定义计算属性 因为箭头函数绑定了父级作用域的上下文,所以 this 将不会按照期望指向Vue
修改前:
computed: {
isShowDialog: () => {
return this.$store.getters.isShowDialog;
}
},
修改后:
computed: {
isShowDialog: function() {
return this.$store.getters.isShowDialog;
}
},