index頁面
1.params
this.$router.push()方法中path不能與params同用,否則param會失效,所以用name來指定頁面,params來傳遞數據內容。
<template> <img src="../../static/images/indexTermianal/teacher.png" alt="" @click ="go()" > </template> <script> methods:{ go:function(){ this.$router.push({ name:'indext', params:{ userId:1 } }) } } </script>
在目標頁面通過this.$route.params獲取參數:
<p>{{this.$route.params.userId}}</p>
2.query
頁面通過path和query傳遞參數,該實例中row為某行表格數據
methods:{
go:function(){
this.$router.push({
path:'/indext',
query:{
userId:1
}
})
}
},
目標頁面this.$route.query.userId獲取數據
<p>{{this.$route.query.userId}}</p>
