问 题
export default{
data(){
return {
thisdata:null
}
},
methods:{
getThisData(){
let that = this;
axios.get('')
.then(function(res){
that.thisdata = res.data;
})
}
},
components:{
mycomponent
}
}
解决方案
这么做就不会报错了,
getThisData(){
let that = this;//可以不用that
axios.get('')
.then(function(res){
that.thisdata = res.data;
})
}
直接用箭头函数:
getThisData(){
axios.get('')
.then((res)=>{
this.thisdata = res.data;
})
}
扫一扫关注IT屋
微信公众号搜索 “ IT屋 ” ,选择关注与百万开发者在一起