When should I make a REST request to retrieve data for a Vue component called Page
, specifically for the properties title
and content
? Also, where is the best place to handle this logic?
Currently, I am trying to fetch the data on the component's ready
hook, but it seems like this function is never being executed:
<template>
<b-container class="bv-example-row">
<h1>{{title}}</h1>
<b-row>
<b-col>
{{content}}
</b-col>
</b-row>
</b-container>
</template>
<script>
import api from '../../api'
export default {
data() {
return {
id: '',
slug: '',
title: '',
content: ''
};
},
ready() {
console.log('foo');
this.fetchData();
},
methods: {
fetchData() {
api.getPageBySlug('sample-page', page => {
this.$set('title', page.title);
this.$set('content', page.content);
});
}
}
};
</script>