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

鍍金池/ 問(wèn)答/HTML/ Axios 方法中怎么修改組件的值?

Axios 方法中怎么修改組件的值?

我有一個(gè)axios封裝的方法:

this.$http.post(Urls.register(), this.formItem).then(function (response) {
          
        }.bind(this))
          .catch(function (response) {
            // 這里我想改變 this.$data.loading=false 怎么做?
            console.log(response)
          })

我在.catch()方法中想要改變一個(gè)組件的值怎么改變?這里好像不能使用this.loading,這里的thisundefined。

回答
編輯回答
雨蝶
this.$http.post(Urls.register(), this.formItem).then(function (response) {
          
        }.bind(this))
          .catch((response) => {
            this.$data.loading=false
            console.log(response)
          })
2017年9月4日 00:08
編輯回答
蔚藍(lán)色
this.$http.post(Urls.register(), this.formItem).then(response=>{
          
        })
          .catch(response=>{
            this指向vue
            console.log(response)
          })



使用箭頭函數(shù),更改this指向Vue,或者你繼續(xù)在catch后面bind(this),但是es6的箭頭函數(shù)已經(jīng)很普及了

2018年5月19日 15:41