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

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

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

1、commonfun.js:
export default{

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

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

3、應用中的一個組件,login.vue:
export default{
...

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

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

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

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

回答
編輯回答
陪她鬧

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

2017年11月6日 10:17