vue-cli 配置路由之间跳转传递参数
1、有2种方式去传参,如下代码:
<template>
<div>
<div>这里是首页</div>
<router-link :to="{name:'reg',params:{user:text}}">注册reg</router-link>
<router-link :to="'/reg/'+text">注册reg</router-link>
</div>
</template>
<script>
export default {
name:"Hello",
data(){
return {
text:"首页传递数据"
}
}
}
</script>
<style>
</style>
特别需要注意的是:传参的时候,to属性必须绑定,即 :to= ,冒号必须有。否则如下图
同时需要注意template下的根标签只能有一个哦,否则会报错。
无:
有:
所以平时我们书写的时候不管怎样,都带上冒号就可以啦。
从图中可以看到:当使用对象形式的时候,是为我们进行了转码;当使用字符串拼接的时候,是直接显示数据。
传递多个参数:
<router-link :to="'/detail/'+title+'/'+price" class="goods-list-link">
{
path:"/detail/:id/:title",
name:"detail",
component:detail
}
<p>{{this.$route.params.id}}</p>
<p>{{this.$route.params.title}}</p>


2、也是2种方式接受参数
<template>
<div>
<div>{{$route.params.user}}</div>
<button @click="write">打印接收的参数</button>
</div>
</template>
<script>
export default {
name:"reg",
data(){
return {
status:true
}
},
methods:{
write(){
console.log(this.$route.params.user);
}
}
}
</script>
<style>
</style>
3、路由配置:
注意:如果传递参数,必须采用动态路由匹配,否则无法跳转。所以reg的path后面必须跟上:user
import Vue from 'vue'
import Router from 'vue-router'
import HelloWorld from '@/components/HelloWorld'
import home from '@/pages/home'
import detail from '../pages/goodsDetail'
import Hello from '@/components/Hello'
import reg from '@/components/reg'
Vue.use(Router)
export default new Router({
routes: [
{
path: '/',
name: 'Hello',
component: Hello
},{
path:"/reg/:user",
name:"reg",
component:reg
}
]
})



vue-cli 配置路由之间跳转传递参数的更多相关文章
- vue 路由 及 跳转传递参数的总结
博客地址:https://ainyi.com/4 vue-router vue-router 是Vue.js官方的路由插件,它和vue.js是深度集成的,适合用于构建单页面应用.vue的单页面应用是基 ...
- vue中的路由的跳转的参数
vue中的路由跳转传参 params 与 query this.$router.push({ name:"detail", params:{ name:'nameValue', c ...
- vue如何配置路由 、获取路由的参数、部分刷新页面、缓存页面
vue如何配置路由 .获取路由的参数.部分刷新页面.缓存页面:http://www.mamicode.com/info-detail-1941546.html vue-router传递参数的几种方式: ...
- vue.js 同级组件之间的值传递方法(uni-app通用)
vue.js 兄弟组件之间的值传递方法 https://blog.csdn.net/jingtian678/article/details/81634149
- vue不通过路由直接获取url中参数的方法示例
vue不通过路由直接获取url中参数的方法示例 vuejs取得URL中参数的值地址:http://localhost:3333/#/index?id=128console.log(this.$rout ...
- Vue编程式路由跳转传递参数
Vue 有时在路由跳转时需要用到一些原页面里的数据,用以下方法: 1.在跳转页的方法里写下query参数 TableChange(scope){ this.$router.push({ path:'d ...
- Vue的自定义组件之间的数据传递
一,父级传向子级 1,在子级的属性中添加props:['myname',......],参数可以传多个,看具体而定: 2,在父级data中定义好需要传递的变量数据,例如name:"rose& ...
- vue.js关于路由的跳转
1.路由demo示例 <div id="app"> <h1>Hello App!</h1> <p> <!-- 使用 route ...
- [转] 微信小程序 页面跳转 传递参数
本文转自:http://blog.csdn.net/qq_31383345/article/details/52795212 微信小程序的页面跳转,页面之间传递参数笔记. CSDN微信小程序开发专栏, ...
随机推荐
- Insertion Sort List——链表的插入排序
Sort a linked list using insertion sort. 这道题跟 Sort List 类似,要求在链表上实现一种排序算法,这道题是指定实现插入排序.插入排序是一种O(n^2) ...
- 转:x64与x86的改变
http://tieba.baidu.com/p/1250470248 x64与x86的改变 硬件要求就是64位的CPU.操作系统也必须是64位的,如果在64位的CPU上安装了32位的操作系统,就算编 ...
- 常用的phpstorm快捷键总结(带截屏版)
常用的phpstorm快捷键总结(带截屏版) 目 录 PhpStorm的快捷键有10类 1.编辑相关 2.搜索/替换 3.被使用搜索 4.项目运行 5.debug相关 6.导航相关 7.重构相关 8. ...
- MFC获取句柄
CWnd *pWnd = GetDlgItem(ID_***); // 取得控件的指针 HWND hwnd = pWnd->GetSafeHwnd(); // 取得控件的句柄
- 针对MySql封装的JDBC通用框架类(包含增删改查、JavaBean反射原理)
package com.DBUtils; import java.lang.reflect.Field; import java.sql.Connection; import java.sql.Dri ...
- 欧拉图 欧拉回路 欧拉通路 Euler
欧拉图 本文链接:http://www.cnblogs.com/Ash-ly/p/5397702.html 定义: 欧拉回路:图G的一个回路,如果恰通过图G的每一条边,则该回路称为欧拉回路,具有欧拉回 ...
- Codeforces Round #424 (Div. 2, rated, based on VK Cup Finals) Office Keys(思维)
Office Keys time limit per test 2 seconds memory limit per test 256 megabytes input standard input o ...
- BZOJ2462[Beijing2011]矩阵模板(二维Hash)
二维矩阵匹配问题,至今不知道Q的范围是多少,反正是要求做到读入复杂度. 二维Hash:就是一维的等效拓展,注意两维的Base不能相同. 其余就是一维Hash和二维前缀和的结合,可以自然溢出,据说概率很 ...
- [BZOJ5011][JXOI2017]颜色
5011: [Jx2017]颜色 Time Limit: 30 Sec Memory Limit: 512 MBSubmit: 84 Solved: 46[Submit][Status][Disc ...
- BZOJ 3343:教主的魔法(分块)
[题目链接] http://www.lydsy.com/JudgeOnline/problem.php?id=3343 [题目大意] 给出一个数列,有区间加法操作,询问区间大于等于c的数字个数 [题解 ...