I'm working with Vue 2.2 and trying to get some data from a http.get request into my data.
I've done the following:
Vue.component('projects', {
template: '',
data: function() {
return {
projects: [],
}
},
created: function() {
// GET request
this.$http.get('http://url/data.json', { headers: { 'Access-Control-Allow-Origin': '*' }}).then(function (data) {
// set data on vm
this.$set('projects', data)
console.log(data);
}
}
});
var project = new Vue({
el: '#projects'
});
This gives me the error:
XMLHttpRequest cannot load http://url/data.json. Response to preflight request doesn't pass access control check: No 'Access-Control-Allow-Origin' header is present on the requested resource. Origin 'null' is therefore not allowed access.
And
default.html:1 Uncaught (in promise) gt {url: "http://url/data.json", ok: false, status: 0, statusText: "", headers: bt…}
Can someone help me with this?
Thanks in advance!