Vue使用axios无法读取data的解决办法

今天发现Vue中使用了axios后,then方法中无法读取到data中的数据了,总是提示 Cannot set property 'xxx' of undefined

上网找了一圈后发现了一下解决方法。

解决办法1:

methods:{
    tap:function(){
        var self=this;
        axios.get('xxxxxx')
        .then(function(result){
            self.message='嘿嘿'
        })
    }
}

解决办法2:

axios.get('xxxxxxxxxxx')
.then((result)=>{
    this.message='嘿嘿'
})
原文地址:https://www.cnblogs.com/dengxiaobo/p/7808728.html