[英]vue router-link not show params on refresh page
when i refresh page, the component "music" see 'params' object empty, can someone help me ?当我刷新页面时,组件“音乐”看到“参数”对象为空,有人可以帮助我吗?
below the code:代码下方:
route.js:
{
path: "/music",
name: "music",
component: music
}
file that call router-link:
<router-link :to="{name:'music', params:{ title:'Musicc'}} ">Music</router-link>
music component:
<template>
<div>
<div>{{title}}</div>
</div>
</template>
<script>
export default {
name: "music",
computed:{
title: function(){
return this.$route.params.title;
}
}
}
</script>
you have to give the param name in path of you route....perhaps it can be the answer你必须在你的路线路径中给出参数名称......也许它可以是答案
route.js:
{
path: "/music/:title",
name: "music",
component: music
}
add props:true
in route.js在 route.js 中添加
props:true
route.js:路线.js:
{
path: "/music",
name: "music",
component: music,
props: true
}
A page refresh is different than clicking on a router link.页面刷新与单击路由器链接不同。 Parameters passed by clicking on a router-link do not persist in the page after a page refresh (as William Wang mentioned).
通过单击路由器链接传递的参数在页面刷新后不会保留在页面中(如 William Wang 所述)。 If you need to persist data in spite of a page refresh, think about using Vuex state management instead of passing lots of parameters around.
如果您需要在页面刷新时保留数据,请考虑使用 Vuex 状态管理而不是传递大量参数。
Here is your problem这是你的问题
in the file that call the router-link在调用路由器链接的文件中
<router-link :to="{name:'music', params:{ title:'Musicc'}} ">Music</router-link>
while in而在
path: "/music"
it should be它应该是
path:"/music/:title"
so it a typo所以这是一个错字
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.