This error is my title and i'm using a combination of VueJs, Vue-Resourse and Laravel.
The error happens when i try assigning 1 local variable to response data that i get back from sending an AJAX request using vue-resource.
Code
Javascript
<script>
flags_page = new Vue({
el: '#body',
data: {
retrievedFlags: {},
chosenFlag: ''
},
ready: function () {
this.getFlagTypes();
},
methods: {
getFlagTypes: function(){
this.$http.get('/getFlags=' + '{{ $id }}', function(data){
//Problem with this line
this.retrievedFlags = data.retrievedFlags;
})
}
}
});
</script>
PHP
public function getFlags($type)
{
$flags = Flags::all();
return [
'retrievedFlags' => $flags,
'chosenFlag' => $type,
];
}
ERROR
vue.min.js:7 Uncaught TypeError: Cannot read property 'get' of undefined
at new n (vue.min.js:7)
at r._bind (vue.min.js:8)
at n (vue.min.js:6)
at vue.min.js:6
at new n (vue.min.js:6)
at n.create (vue.min.js:6)
at r.create (vue.min.js:6)
at r.diff (vue.min.js:6)
at r.update (vue.min.js:6)
at n.update._update (vue.min.js:8)
Again i'm not sure whats causing this I've changed so many things around and i get the same error still. I find this strange because i have other pages that do the exact same things but for some reason this ones throwing up an error.
Its worth nothing that when i console.log() the data object that is returned it shows the data perfectly fine, but the moment i try to assign it to a variable it throws the error.
I also have vuejs included locally along with vue-resource.
Image of me console.logging(this): https://i.sstatic.net/YaAvR.jpg
getfrom$httpis called.$httpdoesn't seem to defined. Can you provide the code where you configure VueResource?getFlagTypesgets called in. Perhapsthisis not what you'd expect. Try aconsole.log(this)before thethis.$http.get