Search code examples
vue.jsvue-cliquasar-frameworkquasar

Quasar CLI VUE instance


Help me solve with the problem please. I am using jquery and jquery-ui to implement drag & drop in QASAR CLI. But I ran into the fact that I cannot access the vue instance from jquery function events, since "this" no longer belongs to Vue, but refers to the selector element. Tell me how I can refer directly to the vue instance as it could be done in cdn version. There you could just give the name app = new Vue ... And then use it as app.data.variable


Solution

  • I believe this is more javascript question, than quasar/vue/jquery. You can easily set value of this by a bind function

    let someFunction = function () {
      console.log(this);
    }
    
    someFunction();
    
    const obj = { 'test': 123 };
    
    someFunction = someFunction.bind(obj);
    
    someFunction();
    

    enter image description here

    Same thing applies to jquery function handlers. I guess you could pass your instance instead of obj

    $(window).ready(function () {
      console.log(this);
    }.bind(obj));