[英]Uncaught ReferenceError: “xxx” is not defined (VUE)
New to Vue, trying to figure out something. Vue 新手,试图弄清楚一些事情。 I'm using this "Data":
我正在使用这个“数据”:
data() {
return {
currentPage: 0,
nextPage: '',
previousPage: '',
left: '',
opacity: '',
scale: '',
}
},
Trying to use the data variables inside a method looks like this:尝试在方法中使用数据变量如下所示:
methods: {
isStageOneDone: function () {
var animating;
if(animating) return false;
animating = true;
this.currentPage;
console.log("CurrentPage =>", currentPage);
}
}
But I keep getting this error:但我不断收到此错误:
Uncaught ReferenceError: currentPage is not defined
未捕获的 ReferenceError:未定义 currentPage
What am I missing?我错过了什么? I looked into the Vue docs and it seems ok I think
我查看了 Vue 文档,我认为似乎还可以
Edit: Is it possible that because of the return() the error occurs?编辑:是否有可能由于 return() 发生错误?
Hi you should define your methods like below嗨,你应该定义你的方法,如下所示
methods: {
isStageOneDone(path, data) {
var animating;
if(animating) return false;
animating = true;
this.currentPage;
console.log("CurrentPage =>", this.currentPage);
}
}
lets try it out i think it will work for you让我们试试吧,我认为它对你有用
You have to add "this" key for access to defined inside data attributes.您必须添加“this”键才能访问定义的内部数据属性。 for example:
例如:
data(){ return{ variable:'example' } }, methods:{ exampleFunc(){ return this.variable; } }
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.