一、传值相关
// 使用 query 传值,使用这种方式传值,请求参数会跟随再Url后,能保证刷新页面依旧能够取到请求的值。
// 如是跳转的页面中存在子路由,而子路由的请求的地址不存在 query 中的参数,则参数会丢失。
// 需要全局共享参数 可以使用 vuex 。
this.$router.push(
url:"",
query:{}
)
使用 this.$route.query.att 进行取值 其中 att 是 query:{} 中包含的参数
// 使用 param 传值,语法于query 相识,Url 中不存在请求的参数。
this.$router.push(
url:"",
param:{}
)
使用 this.$route.param.att 进行取值 其中 att 是 param:{} 中包含的参数
// 使用路由传值
可在目标路由处使用附带请求参数,
this.$router.push("url\"+att)
// 其中路由中需要使用 :/att 占位符标识请求参数
// 例如 path:'/url/:att
使用 this.$route.param.att 进行取值 其中 att 是 param:{} 中包含的参数
二、组件传值相关
// 父/子组件之间通信
// 其中 att 是需要传递的属性 method 是需要传递的方法
<child :att="att" @method="method"></child>
//在子组件中获取属性 使用 props
props:{
att:{
type:Number
default:0
}
}
// 在子组件中调用 父组件的方法
this.$emit('method')
来源:oschina
链接:https://my.oschina.net/u/3744526/blog/4923549