uni app 路由传递参数
A页面传递参数给B页面:
methods: {
goto(type){
//首先创建一个准备传递的参数
var data = {type:type,id:100,name:'你好uni app'};
//在跳转的路由设置一个“ ?data= ”来存储我们准备传递的参数
//传递的参数必须通过JSON.stringify()进行转换
uni.navigateTo({url:"../B?data=" + JSON.stringify(data)});
},
}
B页面接收参数:
//在onLoad拿到A页面发送过来的参数option
onLoad(option) {
//调用receive,并给予参数option
this.receive(option);
},
methods: {
//接收参数
receive(option){
//将option里面我们要的参数data通过JSON.parse()转换回数组
console.log("参数:",JSON.parse(option.data));
//打印结果:参数: {type: 1, id: 100, ca: 500}
},
}