I have a vue page "Edit Post" that relies on the props " post " to display the post content.
export default {
props: ['post'],
data () {
return {
isLoading: false,
posthandle: this.post,
PostForm: new Form({
body: this.post.body,
title: this.post.title : '',
meta_description: this.post.meta_description,
module: this.post.category,
module_id: this.post.source_id
}),
}
},
and I have another page "All Post" where I display all post. While looping through the post I add a button that when clicked opens the "Edit Post" page also passing the post as a props.
<tbody>
<tr class="" v-for="(data,index) in data">
<td class="has-no-head-mobile is-image-cell">
</td>
<td data-label="Title" class="">
<a :href="data.slug" v-text="data.title "></a>
</td>
<td data-label="Author" v-text="data.author" class=""></td>
<td data-label="Category" v-text="data.category" class=""></td>
<td data-label="Date" v-text="data.created_at" class=""></td>
<td data-label="Visits" class="">
<small title="Sep 19, 2018" class="has-text-grey is-abbr-like"
v-text="data.visits"></small>
</td>
<td class="is-actions-cell">
<div class="buttons are-small is-right">
<button type="button" class="button is-danger" @click="deletePost(data.slug, index)">
<span class="icon is-small">
<i class="mdi mdi-trash-can"></i>
</span>
</button>
<button type="button" :class="data.followup ? 'is-success' : '' " class="button" @click="togglelink(data.slug, index)">
<span class="icon is-small" >
<i v-if="data.followup" class="mdi mdi-link-off"></i>
<i v-else class="mdi mdi-link"></i>
</span>
</button>
<!-- =======Router button that leads to edit post====== -->
<router-link :to="{name: 'editpost', params: {post: data}}">
<button type="button" class="button">
<span class="icon is-small">
<i class="mdi mdi-pencil"></i>
</span>
</button>
</router-link>
</div>
</td>
</tr>
</tbody>
Everything works fine but when I refresh the page, I lost the props.
After googling for some time, the only solution I find is to pass the post id through url, then fetch the post from the backend using Axios.
But why should I fetch the data again when I already have it? and that will cause the page to wait a few seconds for the data to be fetched.
Is there another solution to this? Thank you for helping.