vue组件 中 mounted 和 methods 中this指向问题

// temp.vue
export default {
    name: 'temp',
    mounted (){
        console.log(this)
    },
    methods:{
        click:()=>{console.log(this)}
    }
}

起因是想使用vuex在组件点击事件回调中提交 Mutation,结果会报错(找不到commit方法,vuex已经成功引入并注入根组件,mounted钩子里获取this.$store都正常)

打印了下mounted钩子和计算属性里面的this都是 VueComponent

https://img1.mukewang.com/5b889e06000143bf07890400.jpg

而点击事件回调this 

https://img3.mukewang.com/5b889e290001618304760273.jpg

请问这两个this有什么区别吗?



安静的沙漠
浏览 9424回答 1
1回答

安静的沙漠

好吧 我懂了 是箭头函数的锅 不用箭头函数就能获取VueComponent 了
打开App,查看更多内容
随时随地看视频慕课网APP