我在准备好的方法中有这段代码:
this.$http.get('url',{},{
headers: {
"X-App-Token": "token"
}
}).then( (data) => this.$set('cdata',data.data))
.catch( (error) => console.log('Got a problem'+error));
并且它运行良好,问题是当我将它移动到方法对象中的另一个函数时它不起作用。
ready(){
this.getJsonData();
},
methods: {
getJsonData: () => {
this.$http.get('url',{},{
headers: {
"X-App-Token": "token"
}
}).then( (data) => this.$set('cdata',data.data))
.catch( (error) => console.log('Got a problem'+error));
},
},
错误:
src\src\App.vue:23 Uncaught TypeError: Cannot read property '$http' of undefined
//this becomes undefined.