原因:在mounted()钩子函数中,this 指向的是window作用域,所以会出现获取到的data中的数据出现没有定义的情况
解决方法如下:
使用 var that = this ,就可以正常调用了。
mounted(){
var that=this;
console.log(that.name)
}
原因:在mounted()钩子函数中,this 指向的是window作用域,所以会出现获取到的data中的数据出现没有定义的情况
解决方法如下:
使用 var that = this ,就可以正常调用了。
mounted(){
var that=this;
console.log(that.name)
}