一、需求:
tabbar之间跳转页面时,需要传递一个参数。
官方文档明确说明: 跳转tabBar栏的页面只能使用 并且url 路径后面不能传递参数。
二、解决方法:
方法1:setStorageSync(本地缓存)
//index.vue 页
onclick () {
存起来,在另一个页面中获取.
uni.setStorageSync('myIndex', value);
uni.switchTab({
url:'/pages/user/user'
})
}
- 1
- 2
- 3
- 4
- 5
- 6
- 7
// 页(在onShow中从本地缓存中获取出来,进行相关操作)
onShow() {
const myIndex= uni.getStorageSync('myIndex');
console.log(myIndex)
}
- 1
- 2
- 3
- 4
方法2:使用全局变量:
定义全局变量
Vue.prototype.$name = '';
- 1
页面1:
this.$name= "chuanzhi";
uni.switchTab({
url:'/pages/index/index'
})
- 1
- 2
- 3
- 4
- 5
页面2:
(注意一定要放在onShow生命周期里面及时更新数据,因为tabBar会有缓存机制此时再次进入页面onLoad不会执行)
onShow(){
this.info.name = this.$name//赋值取得参数
}
- 1
- 2
- 3
- 4
- 5
此时 就是页面传递过来的参数