Reputation: 1384
I want to make a page refresh after I click on the router-link. How can I do that with Vue JS in Laravel? but I don't want to use onclick="window.location.reload();"
My code is something like that-
Code in app.js
{
path: '/publisher',
component: require('./components/Publishers.vue').default,
}
Code in Master.blade.php
<li> <router-link to="/publisher" class="nav-link" >انتشارات</router-link></li>
Code in publishers.vue
export default {
components: {
},
data() {
return {
Publishers: {},
};
},
computed: {},
methods: {
loadPublishers() {
this.$Progress.start();
axios.get("api/publisher").then(({ data }) => (this.Publishers = data));
},
},
created() {
this.loadPublishers();
// load the page after 3 secound
Fire.$on("refreshPage", () => {
this.loadPublishers();
});
}
};
Upvotes: 3
Views: 10604
Reputation: 1554
You can add a name
property to the route
object and instead of using <router-link>
, you can use an a
tag like this
<a :href="$router.resolve({name: 'publisher'}).href">link</a>
Your route object will be like
{
path: '/publisher',
name: 'publisher',
component: require('./components/Publishers.vue').default,
}
The name field in the router
is not mandatory, it is using only for making it simple to use.
Upvotes: 7