问题: 如何在Vue中取得函数回调的值
工具js中代码
this.upload = function (url, callback) {
$.ajax({
// code
},
success: function (res) {
callback(res)
},
error: function (err) {
console.log(err)
}
}
Vue中的代码
uploadAudio () {
recorder.upload('hello world', function (res) {
this.recorderText = res.data
console.log(res.data)
})
},
看题主代码,this.recorderText在function(res){}里面,this是指向内部,不是vue实例,所以获取不到data里面的recorderText;
解决方式: