I have a Vuex store
/store/articles.js
export const state = () => ({
article:'',
})
export const mutations = {
setArticle(state, payload) {
state.article= payload.data;
}
}
export const actions = {
async getArticle ({ commit }, id) {
try {
const { data } = await axios.post('http://test.local/api/getArticle',id);
commit('setArticle', { data })
} catch (e) {
console.log(e);
}
}
}
my API returns a JSON like example this
{
"id": 1,
"title": "some title",
"content": "some content",
"image": "article_img1.jpg"
}
there is my page and content from API
/pages/article/slug.vue
<template>
<div>
<h4>{{ article.title }}</h4>
<img :src="'/images/'+article.image" />
<div v-html="article.content" />
</div>
</template>
<script>
export default {
computed:{
article(){
return this.$store.dispatch('getArticle',1)
},
},
}
</script>
Content appears fine, but when I look at the content page code, there is no content. How to make the content prerendered, on this way?
And how to generate static pages from an API, do I need to use @nuxt/content ? I am trying this, but it looks like works only from .md
or .json
files, I don't understand how to generate automatically with some API fetching.