账号密码登录
微信安全登录
微信扫描二维码登录

登录后绑定QQ、微信即可实现信息互通

手机验证码登录
找回密码返回
邮箱找回 手机找回
注册账号返回
其他登录方式
分享
  • 收藏
    X
    代码中打印出的_self,this对象为什么都嵌套在一个a属性中????
    53
    0

    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调用func时,执行到return时出错,cannot read property '001'of undefined;打印出的this对象为什么都嵌套在一个a属性中,未知原因,如下:
    {

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

    }
    修改commonfun.js的func函数return this.a.va[retcode]可正常返回;不知a的出处?

    0
    打赏
    收藏
    点击回答
    您的回答被采纳后将获得:提问者悬赏的 11 元积分
        全部回答
    • 0
    更多回答
    扫一扫访问手机版
    • 回到顶部
    • 回到顶部