天天看点

【uni-app】 带参数跳转

传参页面:

uni.navigateTo({
    url: 'test?id=1&name=uniapp'
});      
methods: {
    comment:function(id){
        uni.navigateTo({
            //多个参数用&拼接:url: '../comment/comment?id='+id+'&name='+name
            url: '../comment/comment?id='+id
        });
    },
}      

注意:当需要传的参数过多时可以使用es6的模板字符串拼接

var name = 'moss';
var age = 18;
console.log(`My name is ${name} and I am ${age} years old`);
// 打印结果:My name is moss and I am 18 years old      

接受参数页面

onLoad:function(option){//opthin为object类型,会序列化上页面传递的参数
  console.log(option.id);//打印出上页面传递的参数
}      
<navigator :url="'/pages/test/test?item='+ encodeURIComponent(JSON.stringify(item))"></navigator>      
onLoad(option) {
    const item = JSON.parse(decodeURIComponent(option.item));
}