Vue's method of jumping parameters: 1. Jump parameters through the params or query attribute of the router-link tag; 2. Pass "this.$router.push({name:'Route naming' ,params:{parameter name:parameter value..}})" statement to jump to transfer parameters.
The operating environment of this tutorial: windows7 system, vue2.9.6 version, DELL G3 computer.
First create readDetail.vue and register the route in index.js.
Page delivery method:
<router-link> <button>跳转</button> </router-link> 1. path -> 是要跳转的路由路径,也可以是路由文件里面配置的 name 值,两者都可以进行路由导航 2. params -> 是要传送的参数,参数可以直接key:value形式传递 3. query -> 是通过 url 来传递参数的同样是key:value形式传递
this. $router.push({name:'Route naming',params:{parameter name:parameter value,parameter name:parameter value}})
this.$router.push({ path: 'yourPath', name: '要跳转的路径的 name,在 router 文件夹下的 index.js 文件内找', params: { key: 'key', msgKey: this.msg } /*query: { key: 'key', msgKey: this.msg }*/ })
this.$route.params.Parameter name
this.$route.query.Parameter name
Experiment (including two methods) :
Transmitting page:
<router-link> <button>跳转</button> </router-link> <button>传递</button> ----------------------------------------------------------------------------------------- export default { name: 'reads', data () { return { msg: 'msg test.' } },
Receive page:
<p> </p><p>Num:{{ myIndex }}</p> <p>{{ msg }}</p> ----------------------------------------------------------- data () { return { msg: '', // 保存传递过来的index myIndex: '' } ----------------------------------------------------------- mounted: function () { this.msg = this.$route.params.msgKeyOne this.myIndex = this.$route.params.msgKey console.log(this.myIndex) }
Experiment result:
##Related recommendations:《vue.js tutorial》
The above is the detailed content of How to pass parameters when jumping in vuejs. For more information, please follow other related articles on the PHP Chinese website!