使用params传参 ,不能使用path 只能使用name

使用params传参,刷新参数会消失

router/index.js

import Vue from 'vue'
import Router from 'vue-router'
import login from '@/components/login/login'
import index from '@/components/index/index'
import HelloWorld from '@/components/HelloWorld' Vue.use(Router) export default new Router({
routes: [
{
path: '/',
redirect: '/login'
},
{
path:'/index',
name : 'index',
component : index
},
{
path:'/login',
name : 'login',
component : login
}
]
})

login页面(params传参)

this.$router.replace({name:'index',params:{
username:successResponse.data.object.username,
phone:successResponse.data.object.phone
}
})

index页面

<template>
<div>
<hr>
<div>
This is username. <span v-text="username"> </span> <br>
This is the phone. <span v-text="phone"> </span> <br>
This is also username {{$route.params.username}}
</div>
<hr>
</div>
</template>
<script>
export default {
name : 'index',
//created 钩子函数 Vue 初始化时执行
created:function() {
this.getParams();
},
watch:{
//监测路由变化,只要变化了就调用路由参数方法将数据存储本组件即可
'$route':'getParams'
},
methods:{
getParams:function() {
//取得路由带过来的参数
let routeUsername = this.$route.params.username
let routePhone = this.$route.params.phone
//将数据放在当前组件的数据内
this.username = routeUsername
this.phone = routePhone
},
}
}
</script>

login页面(query传参)

this.$router.replace({path:'/index',query:{
username:successResponse.data.object.username,
phone:successResponse.data.object.phone
}
})

index页面

<template>
<div> <hr>
<div>
This is username. <span v-text="username"> </span> <br>
This is the phone. <span v-text="phone"> </span> <br>
This is also username {{$route.query.username}}
</div>
<hr> </div>
</template>
<script>
export default {
name : 'index',
//created 钩子函数 Vue 初始化时执行
created:function() {
this.getQuerys();
},
watch:{
//监测路由变化,只要变化了就调用路由参数方法将数据存储本组件即可
'$route':'getQuerys',
},
methods:{
getQuerys:function() {
//取得路由带过来的参数
let routeUsername = this.$route.query.username
let routePhone = this.$route.query.phone
//将数据放在当前组件的数据内
this.username = routeUsername
this.phone = routePhone
},
}
}
</script>

最新文章

  1. java 特性
  2. 利用fiddler模拟发送json数据的post请求
  3. [shell]. 点的含义
  4. Android简易数据存储之SharedPreferences
  5. Java并发——同步容器与并发容器
  6. 【Android】listview优化
  7. 基础算法-查找:线性索引查找(I)
  8. [原创].NET 业务框架开发实战之十 第一阶段总结,深入浅出,水到渠成(后篇)
  9. Thrift RPC实战(一).初次体验Thrift
  10. andorid之摄像头驱动流程--MTK平台
  11. 搭建Elasticsearch集群常见问题
  12. MyBatis 框架的搭建和配置
  13. Scheme来实现八皇后问题(1)
  14. 2019春第八周作业Compile Summarize
  15. 利用Python通过频谱分析和KNN完成iphone拨号的语音识别
  16. java使用POI解析2007以上的Excel表格
  17. Codeforces 1136E Nastya Hasn&#39;t Written a Legend 线段树
  18. Solidity字符串和函数
  19. 邮件服务器fixpost服务(1)
  20. dedecms添加新模型

热门文章

  1. Python 自己实现可迭代对象
  2. View Controller Programming Guid for iOS 笔记
  3. MySQL主从复制(Centos6.3&amp;MySQL5.6)
  4. Scala 中 call by name &amp; call by value 的区别
  5. Go语言的反射
  6. 利其器:无法在 &quot;.vscode&quot; 文件夹()内创建 &quot;launch.json&quot; 文件。
  7. POI进行导出时候发现有不可读取的内容
  8. Windows 对外开放端口号
  9. UML之九种图
  10. Codeforces Round #609 (Div. 2) C. Long Beautiful Integer