Answer the question
In order to leave comments, you need to log in
How to set the data json property in VueJS to the object from the Facebook response?
<script type="text/javascript">
new Vue({
el: '#app',
data: [],
methods: {
connectToFacebook: function() {
FB.login(function(response) {
if (response.authResponse) {
$.getJSON("{{ route('callback') }}", function(data){
console.log(data[0]);
});
} else {
return false;
}
});
}
}
});
</script>
<script>
window.fbAsyncInit = function() {
FB.init({
appId: '{{ env('FACEBOOK_APP_ID') }}',
cookie: true, // This is important, it's not enabled by default
version: 'v2.8'
});
};
(function(d, s, id){
var js, fjs = d.getElementsByTagName(s)[0];
if (d.getElementById(id)) {return;}
js = d.createElement(s); js.id = id;
js.src = "//connect.facebook.net/en_US/sdk.js";
fjs.parentNode.insertBefore(js, fjs);
}(document, 'script', 'facebook-jssdk'));
</script>
Answer the question
In order to leave comments, you need to log in
data: {
facebookData:null
},
methods: {
connectToFacebook: function() {
var self = this;
FB.login(function(response) {
if (response.authResponse) {
$.getJSON("{{ route('callback') }}", function(data){
console.log(data[0]);
self.facebookData = data;
});
} else {
return false;
}
});
}
}
I can’t assign the value of the received json-a to the data property in any way ???
function(){...function(){..
do not leave a trace of the context in which data is located, respectively, you received json, but assign a value to something wrong. Use arrow functions to avoid such problems in the future.
Didn't find what you were looking for?
Ask your questionAsk a Question
731 491 924 answers to any question