鍍金池/ 問答/Java  HTML/ 代碼中打印出的_self,this對(duì)象為什么都嵌套在一個(gè)a屬性中????

代碼中打印出的_self,this對(duì)象為什么都嵌套在一個(gè)a屬性中????

1、commonfun.js:
export default{

va:{
    '000': "錯(cuò)誤0",
    '001': "錯(cuò)誤1",
    '002': "錯(cuò)誤2'
    
},
func:(retcode)=>{
    console.log(this);
    return this.va[retcode];
}

}
2、main.js:
import vue相關(guān)依賴
import commonfun from commonfun
Vue.prototype.$utils=commonfun;

3、應(yīng)用中的一個(gè)組件,login.vue:
export default{
...

methods:{
    login(){
        this.$utils.func('001')
    }
}

}
當(dāng)login調(diào)用func時(shí),執(zhí)行到return時(shí)出錯(cuò),cannot read property '001'of undefined;打印出的this對(duì)象為什么都嵌套在一個(gè)a屬性中,未知原因,如下:
{

a:{
   va:  Object,
   func: function..
}

}
修改commonfun.js的func函數(shù)return this.a.va[retcode]可正常返回;不知a的出處?

回答
編輯回答
陪她鬧

_self就是this,為什么不是同一個(gè)。而箭頭函數(shù)的this為上一級(jí)的this,至于是不是a就不知道了,你這只寫了export也不知道你在哪用的。

2017年11月6日 10:17