鍍金池/ 問答/HTML/ 使用axios的時候,`bind(this)`是指的什么意思?

使用axios的時候,`bind(this)`是指的什么意思?

在使用axios的時候,bind(this)是指的什么意思?

this.$http.post(Urls.register(), this.formItem).then(function (response) {
          
        }.bind(this))
          .catch(function (response) {
            console.log(response)
          })

回答
編輯回答
情未了

其實也是會用到的。如果你在b環(huán)境里面調(diào)用A環(huán)境的方法并且訪問A環(huán)境的屬性那么bind(this)還是非常有效果的,如果你的this指代當前環(huán)境,那么 () => { this } 就夠用了

2018年9月6日 18:39
編輯回答
胭脂淚

更改this指向,建議用箭頭函數(shù)(這樣不需要改this指向問題了)
this.$http.post(Urls.register(), this.formItem).then(response=>{

      
    })
      .catch(err=>{
        console.log(response)
      })
2017年4月8日 01:40