在线观看不卡亚洲电影_亚洲妓女99综合网_91青青青亚洲娱乐在线观看_日韩无码高清综合久久

鍍金池/ 問(wèn)答/HTML/ 在Vue如何取得函數(shù)回調(diào)的值

在Vue如何取得函數(shù)回調(diào)的值

問(wèn)題: 如何在Vue中取得函數(shù)回調(diào)的值

clipboard.png

工具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是指向內(nèi)部,不是vue實(shí)例,所以獲取不到data里面的recorderText;
解決方式:

1: uploadAudio () {
      let that = this;
      recorder.upload('hello world', function (res) {
        that.recorderText = res.data
        console.log(res.data)
      })
}
2: uploadAudio () {
      recorder.upload('hello world',(res) => {
        that.recorderText = res.data
        console.log(res.data)
      })
}
2018年5月16日 04:53