【发布时间】:2021-06-16 20:11:20
【问题描述】:
Vue 新手,试图弄清楚一些事情。 我正在使用这个“数据”:
data() {
return {
currentPage: 0,
nextPage: '',
previousPage: '',
left: '',
opacity: '',
scale: '',
}
},
尝试在方法中使用数据变量如下所示:
methods: {
isStageOneDone: function () {
var animating;
if(animating) return false;
animating = true;
this.currentPage;
console.log("CurrentPage =>", currentPage);
}
}
但我不断收到此错误:
Uncaught ReferenceError: currentPage is not defined
我错过了什么?我查看了 Vue 文档,我认为似乎还可以
编辑: 有没有可能是因为return()而发生错误?
【问题讨论】:
-
括号必须包裹在返回的对象周围,否则将无法正确解释。 (编辑:这是因为
return {将被解释为return {;,因为所谓的Automatic Semicolon Insertion。有关更多信息,请参阅stackoverflow.com/questions/8528557/…) -
我不明白你的意思,对不起
-
函数中的代码没有多大意义。为了让任何人都能够帮助您,我们至少需要了解您想要实现的目标。作为旁注,您的代码确实尝试使用尚未在您的函数范围内定义的变量(
currentPage)(因为this.currentPage不是currentPage)。但是,即使您在使用它之前确实定义了它,您也只会删除错误,它不会做任何事情。那么,您想用该代码做什么?
标签: javascript vue.js