0
votes

New to Vue, trying to figure out something. 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

What am I missing? I looked into the Vue docs and it seems ok I think

Edit: Is it possible that because of the return() the error occurs?

2
Parentheses must be wrapped around objects which are returned or it will not be interpreted correctly. (Edit: This is because return { will be interpreted as return {; due to what's known as Automatic Semicolon Insertion. For more info, see stackoverflow.com/questions/8528557/…)Edric
I don't understand what u mean,I'm sorryuser8395584
The code inside your function doesn't make much sense. In order for anyone to be able to help you, we'd need to at least understand what it is you are trying to achieve. As a sidenote, your code does try to use a variable (currentPage) which has not yet been defined in the scope of your function (because this.currentPage is not currentPage). However, even if you did define it prior to using it, you'd only remove the error, it wouldn't do anything. So, what are you trying to do with that code?tao

2 Answers

0
votes

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

0
votes

You have to add "this" key for access to defined inside data attributes. for example:

data(){
return{
  variable:'example'
}
},
methods:{
  
  exampleFunc(){
  
  
  return this.variable;
  }
}