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='嘿嘿' })
春花秋月何时了?往事知多少。小楼昨夜又东风,故国不堪回首月明中。
雕栏玉砌应犹在,只是朱颜改。问君能有几多愁?恰似一江春水向东流。