1.methods 中 为何不能使用箭头函数
- methods: {
- increment(index) {
- this.counter ++; //这里的 this 指向组件实例,是 vue 源码中对methods 中所有函数进行了遍历,通过 bind 来绑定了 this
- },
- increment:(index) => this.counter ++; //这里的 this 指向 windows,不能写箭头函数
- //箭头函数使用this的查找规则:它会在自己的上层作用域中来查找this
- ,
- }