vue路由传参常用写法,vue路由传参params和query差别,params刷新页面丢失参数,query不会丢失
2019-06-22 17:29
726 查看
<template> <div class="hello"> <!-- to这样过去得也是params拿。但是刷新页面可以拿到 --> <router-link :to="'/news/'+id">跳啊跳</router-link> <h1 @click="toParams">我是params去新页面</h1> <router-link :to="{name:'par',params:{'id':id}}">我是router-linlk_to是对象形式过去的;params去新页面</router-link> 下面是子组件 <p @click="toOne">点我去aaone</p> <p @click="toTwo">点我去two</p> <router-view></router-view> </div> </template> <script> export default { name: 'HelloWorld', data () { return { msg: 'Welcome to Your Vue.js App', id:'222' } }, // 主要是为了证实 params 刷新页面 参数会丢失。 而 query不会丢失。 methods:{ toOne() { this.$router.push({name:'one',params:{'id':'111'}}) }, toTwo(){ // 子组件 如果要使用 path+query传参 。记得路由.js的path值不要和name值一样,要不把父路由地址和它拼过去 /two 因为父正好是/ // name 可以 和params,query搭配。但是path只能和query搭配 this.$router.push({name:'tw',query:{'i':'111'}}) }, toParams(){ this.$router.push({name:'par',params:{'id':'ppp'}}) } } } </script> <!-- Add "scoped" attribute to limit CSS to this component only --> <style scoped> h1, h2 { font-weight: normal; } ul { list-style-type: none; padding: 0; } li { display: inline-block; margin: 0 10px; } a { color: #42b983; } </style>
import Vue from 'vue' import Router from 'vue-router' import HelloWorld from '@/components/HelloWorld' const one = () => import ('@/view/one.vue'); const two = () => import('@/view/two.vue') const news = () =>import('@/view/news.vue') const par = () => import('@/view/params') Vue.use(Router) export default new Router({ routes: [ { path: '/', name: 'HelloWorld', component: HelloWorld, children:[{ path:'one', name:'one', component:one, },{ path:'two', name:'tw', component:two } ] }, { path:'/news/:id', name:'news', component:news }, { path:'/par', name:'par', component:par } ] })
相关文章推荐
- vue 路由传递参数,刷新页面后参数丢失
- vue.js用vue-router路由传参时页面刷新后参数消失的问题
- 解决vue页面刷新或者后退参数丢失的问题
- vue 路由传参 params 与 query两种方式的区别
- vue刷新页面带来的参数丢失
- vue 路由传参用query或params
- 详解解决Vue相同路由参数不同不会刷新的问题
- vue路由传参query和params的区别
- Vue(Router) query与params传参/接收参数的区别
- vue路由传参params和query区别
- vue 路由传参 params 与 query两种方式用和的区别
- vue小知识 路由传参数params,query
- vue页面刷新或者后退参数丢失的问题
- vue 路由传参 params 与 query两种方式的区别
- vue传参页面刷新数据丢失问题
- vue学习笔记:7.2.路由规则中定义参数-query传参与params传参
- vue通过 vue.mixin(混合)实现 任意页面记录滚动条位置(路由router.query参数一致) 并跳转到上次的位置
- vue刷新页面带的参数丢失问题
- VUE通过路由 QUERY传递参数
- vuex + sessionstorage 解决vue项目刷新后页面空白/数据丢失