1.对按钮绑定跳转事件
主页面
<template>
<view>
<button @click="pass">跳转传递数据</button>
</view>
</template>
<script>
export default {
data() {
return {
// 需要传递的参数
sss:222,
}
},
methods: {
pass(){
// 页面跳转
uni.navigateTo({
url:'/pages/fenlei/ziyemian/ziyemian?code=' + this.sss, // ?code= 添加在你地址的后面 ,code是自定义的
})
}
}
}
</script>
2.接收数据
跳转页面
<template>
<view>
跳转页面
</view>
</template>
<script>
export default {
data() {
return {
send:'' //保存传过来的数值
}
},
onLoad(e) { //在加载时获取跳转后的数据
console.log(e) // 传递过来的是个对象 {code:"222"}
this.send = e.code // code为上一个页面传递时自定义的参数
},
methods: {
}
}
</script>
注意*:以上方法只适用于传递单个数值,不支持传递数组,想要传递数组可以这样传递
pass(e){
// 页面跳转
uni.navigateTo({
url:'/pages/fenlei/ziyemian/ziyemian?code=' + this.group.aa +"=" +this.group.bb, // ?code= 添加在你地址的后面
})
}
然后在跳转后的页面编辑
onLoad(e) {
console.log(e) // 传递过来的是个对象 {code:"222"}
let arr = e.code.split('=')
this.send = arr[0] // code为上一个页面传递时自定义的参数
},
总结一下:主页面点击跳转按钮,一块把数值传递给跳转到的页面,在跳转的页面加载时就获取数据,进行别的操作