【发布时间】:2018-03-05 11:01:00
【问题描述】:
为什么在mounted 中使用() => 和function() 的结果不同:
export default {
mounted: () => {
this.socket = 'something'
console.log('mounted')
},
methods: {
submitMessage() {
console.log(this.socket) // undefined
}
}
}
使用function():
export default {
mounted: function() {
this.socket = 'something'
console.log('mounted')
},
methods: {
submitMessage() {
console.log(this.socket) // something
}
}
}
有什么想法吗?
【问题讨论】: