[Vuejs]-Accessing vue instance in controller's function

0๐Ÿ‘

โœ…

I found out the solution,
It is possible to use a property available in directive object, it is this.vm which is actually the vue model the for the directive, thus is possible use this.vm and assign it to some variable before invoking the function and thus use the name of the variable to which this.vm was assign as singleton function call.

Vue.directive('fetch',function(value){
value["url"].isLiteral = true;
var model = this.vm;
qwest.post(value["url"]).then(
    function(response){
        console.log(response);
        if (response["CODE"] == 1){
            console.log(response["RESULT"]);
            model.result = response["RESULT"];
            model.error = "";
        }else{
            model.result = "";
            model.error = response["ERROR"];
        }
    }
).catch(
        function(e,response){
            model.error = response["ERROR"];
        }
    );
})
๐Ÿ‘คJibin Mathew

Leave a comment