- Add a selectedPostDetails data property in the state and add the corresponding getter and mutation:
state () {
return {
// ...
// Fetched details for the selected post
selectedPostDetails: null,
}
},
getters: {
// ...
selectedPostDetails: state => state.selectedPostDetails,
},
mutations: {
// ...
selectedPostDetails (state, value) {
state.selectedPostDetails = value
},
},
- In the selectPost, fetch the details with a request to the /post/<id> route on the server:
async selectPost ({ commit }, id) {
commit('selectedPostDetails', null)
commit('selectedPostId', id)
const details = await $fetch(`posts/${id}`)
commit('selectedPostDetails', details)
},
- Also add a new unselectPost action:
unselectPost ({ commit }) {
commit('selectedPostId', null)
},
..................Content has been hidden....................
You can't read the all page of ebook, please click
here login for view all page.