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

Posted 小楼昨夜又东风

tags:

篇首语:本文由小常识网(cha138.com)小编为大家整理,主要介绍了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=‘嘿嘿‘
})

以上是关于Vue使用axios无法读取data的解决办法的主要内容,如果未能解决你的问题,请参考以下文章