我想在单击路由器链接后刷新页面。我如何在 Laravel 中使用 Vue JS 做到这一点?但我不想使用onclick="window.location.reload();"
我的代码是这样的——
app.js 中的代码
{
path: '/publisher',
component: require('./components/Publishers.vue').default,
}
Run Code Online (Sandbox Code Playgroud)
Master.blade.php 中的代码
<li> <router-link to="/publisher" class="nav-link" >????????</router-link></li>
Run Code Online (Sandbox Code Playgroud)
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();
});
}
};
Run Code Online (Sandbox Code Playgroud)
小智 5
您可以name向route对象添加一个属性,而不是使用<router-link>,您可以使用这样的a标签
<a :href="$router.resolve({name: 'publisher'}).href">link</a>
Run Code Online (Sandbox Code Playgroud)
你的路线对象会像
{
path: '/publisher',
name: 'publisher',
component: require('./components/Publishers.vue').default,
}
Run Code Online (Sandbox Code Playgroud)
中的名称字段router不是强制性的,它仅用于使其易于使用。
| 归档时间: |
|
| 查看次数: |
5305 次 |
| 最近记录: |