let others = Vue.extend({
template: <button @click="test">当前值:{{1111111$store.state.num}}</button>
,
methods: {
test() {
console.log(222222this.$store)
console.log(333333$store)
}
}
})
111111
22222
33333
$store是有什么不同吗?
template里面的$store可以不加this
但是在methods里面的$store则必须添加this
不然333333就会报错
这是什么原因呢
他们不都是js环境吗
有什么区别在这当中呢?
methods里面的this指向的是VueComponent,
template模板里面的js环境应该是全局的,还是对应的others组件的
和methods里面的并不相同,
不确定