Loading

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='嘿嘿'
})
posted @ 2017-11-09 12:02  木头人4216  阅读(2779)  评论(0编辑  收藏  举报