[英]Vuejs and Page Refresh on <router-link> click
I want to make a page refresh after I click on the router-link.我想在单击路由器链接后刷新页面。 How can I do that with Vue JS in Laravel?我如何在 Laravel 中使用 Vue JS 做到这一点? but I don't want to use onclick="window.location.reload();"
但我不想使用onclick="window.location.reload();"
My code is something like that-我的代码是这样的——
Code in app.js app.js 中的代码
{
path: '/publisher',
component: require('./components/Publishers.vue').default,
}
Code in Master.blade.php Master.blade.php 中的代码
<li> <router-link to="/publisher" class="nav-link" >انتشارات</router-link></li>
Code in publishers.vue 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();
});
}
};
You can add a name
property to the route
object and instead of using <router-link>
, you can use an a
tag like this您可以向route
对象添加name
属性,而不是使用<router-link>
,您可以使用这样的a
标签
<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. router
的名称字段不是强制性的,它只是为了使用方便。
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.