vue路由组件跳转传参中文乱码解决
-在路由传参
this.$router.push({
path:"/index",
query:{
msg:encodeURI("我是消息")
}
})
- 在下一个页面加载时截取导航栏中的参数
- 用this.$读取
- 下一个组件加载时用created
- 在获取导航栏中的信息时,提前用**decodeURI(this.$)**包住
- 就可以解决中文乱码,再将自己想要的数值赋值到定义的变量
<script>
export default {
data(){
return{
msg:""
}
},
methods:{
url(){
// 上一个页面需要使用query传参,并且encodeURL下
this.msg=decodeURI(this.$route.query.msg); // mag是上一个query传递的参数key
}
},
created(){
this.url();
}
}
</script>
希望对你们有帮助