S
S
sacden7772020-09-15 17:23:34
Vue.js
sacden777, 2020-09-15 17:23:34

VUE + VK API + JSONP - how to make a request?

Please tell me, the question concerns a cross-domain request using JSONP and VUE JS and the VK API
There is a vk FAQ with an example of use - (clause 4.1.) Everything works on pure javascript, but the problem arises with the transfer to the project in vue.

JSONP returns a callback function. The question is how to correctly register it in VUE? When I use the code (see below), I get an error - Uncaught ReferenceError: callbackFunc is not defined, which means - the function is undefined. But how to define it then? I've looked all over the internet and found nothing. I would be very grateful if you could tell me.

methods: {
        callbackFunc: function (result) {
        console.log(result.response)
        },
         addCounter: function(){
         let script = document.createElement( 'script' );
         //function callbackFunc(result){};
         script.src = "https://api.vk.com/method/users.get?fields=id,first_name,last_name,photo_big&v=5.92&access_token=" + mytoken + "&callback=callbackFunc";
         document.getElementsByTagName( 'head' )[ 0 ].appendChild( script );
       },

Answer the question

In order to leave comments, you need to log in

Didn't find what you were looking for?

Ask your question

Ask a Question

731 491 924 answers to any question