So I am trying to use the following component within Vue JS:
Vue.component('careers', {
template: '<div>A custom component!</div>',
data: function() {
var careerData = [];
client.getEntries()
.then(function (entries) {
// log the title for all the entries that have it
entries.items.forEach(function (entry) {
if(entry.fields.jobTitle) {
careerData.push(entry);
}
})
});
return careerData;
}
});
The following code emits an error like so:
[Vue warn]: data functions should return an object:
https://v2.vuejs.org/v2/guide/components.html#data-Must-Be-a-Function
(found in component <careers>)
However as you can see I am running a foreach through all of my Contentful entries
, then each object within entries is being pushed to an array, I then try to return the array but I get an error.
Any idea how I can extract all of my entries
to my data object within my component?
When I use the client.getEntries()
function outside of my Vue component I get the following data: