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 related dependencies
import commonfun from commonfun
Vue.prototype.$utils=commonfun;
3. A component in the application, login.vue:
export default {
.
methods:{
login(){
this.$utils.func("001")
}
}
}
when login calls func, there is an error executing return. Why, cannot read property "001"of undefined; prints out this objects are all nested in a property. Unknown reasons are as follows:
{
a:{
va: Object,
func: function..
}
}
modify commonfun.js "s func function return this.a.va [retcode] can return normally; do not know the origin of a?