0

I have a vue object and in the mounted method I test for a scroll event on the browser

mounted() {

self= this;

 $(window).scroll(function(){
          $.get("/works?start="+$('#loaded_max').val(), function(loaded){
            self.work = loaded;
            console.log(self);
          });

    });

console.log(self) //returns window

console.log(this) //returns ajax

How do I access the vue object? Specifically the data so I can update the variable.

1 Answer 1

1

Self appears to be window, any other variable works

so

 mounted() {

let myvue = this;

 $(window).scroll(function(){
          $.get("/works?start="+$('#loaded_max').val(), function(loaded){
            myvue.work = loaded;
            console.log(myvue.work);
          });

    });

I have always used that technique to reference the 'current object' when scope is an issue but it obviously has issues when you need to reference something other than the window.

Sign up to request clarification or add additional context in comments.

Comments

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.