当前位置:网站首页>通过uview让tabbar根据权限显示相应数量的tabbar
通过uview让tabbar根据权限显示相应数量的tabbar
2022-06-27 06:47:00 【会说话的字符】
通过uview让tabbar根据权限显示相应数量的tabbar
搭好uview-app架子
正常配置好page.json的tabbar项
配置完成后通过vuex 来控制 tabbar list的变化
这上面的配置中的路径前面必须加 /
index.js
import Vue from 'vue';
import Vuex from 'vuex'
Vue.use(Vuex)
const tabbar=[{
"pagePath": "/pages/index/index",
"iconPath": "/static/index.png",
"selectedIconPath": "/static/index-selected.png",
"text": "首页",
"midButton": false,
}, {
"pagePath": "/pages/center/index",
"iconPath": "/static/center.png",
"selectedIconPath": "/static/center-selected.png",
"text": "我",
"midButton": false,
},{
"pagePath": "/pages/perms/perms",
"iconPath": "/static/center.png",
"selectedIconPath": "/static/center-selected.png",
"text": "权限页",
"midButton": false,
}]
const store=new Vuex.Store({
state:{
tabbar_readonly:tabbar,
tabbar:tabbar
},
mutations:{
$uStore(state, payload) {
// 判断是否多层级调用,state中为对象存在的情况,诸如user.info.score = 1
let nameArr = payload.name.split('.');
let saveKey = '';
let len = nameArr.length;
if(nameArr.length >= 2) {
let obj = state[nameArr[0]];
for(let i = 1; i < len - 1; i ++) {
obj = obj[nameArr[i]];
}
obj[nameArr[len - 1]] = payload.value;
saveKey = nameArr[0];
} else {
// 单层级变量,在state就是一个普通变量的情况
state[payload.name] = payload.value;
saveKey = payload.name;
}
}
}
})
export default store
$u.mixin.js
import {
mapState
} from 'vuex'
import store from "@/store"
// 尝试将用户在根目录中的store/index.js的vuex的state变量,全部加载到全局变量中
let $uStoreKey = [];
try {
$uStoreKey = store.state ? Object.keys(store.state) : [];
} catch (e) {}
module.exports = {
created() {
// 将vuex方法挂在到$u中
// 使用方法为:如果要修改vuex的state中的user.name变量为"史诗" => this.$u.vuex('user.name', '史诗')
// 如果要修改vuex的state的version变量为1.0.1 => this.$u.vuex('version', '1.0.1')
this.$u.vuex = (name, value) => {
this.$store.commit('$uStore', {
name,
value
})
}
},
computed: {
// 将vuex的state中的所有变量,解构到全局混入的mixin中
...mapState($uStoreKey)
}
}
main.js
import store from './store/index.js'
const storeMixins = require('./store/$u.mixin.js');
Vue.mixin(storeMixins)
const app = new Vue({
store,
...App
})
app.$mount()
在每个tabbar页面当中使用 u-tabbar 组件
由于 vuex 中的state.tabbar已经全局混入了,所以每个tabbar页面已经有 this.tabbar 这个变量.
在组件的list属性放入tabbar就行
边栏推荐
- Compatibility comparison between tidb and MySQL
- Visual Studio VS 快捷键使用大全
- winow10安装Nexus nexus-3.20.1-01
- The fourth question of the 299th weekly match 6103 Minimum fraction of edges removed from the tree
- Cloud-Native Database Systems at Alibaba: Opportunities and Challenges
- 从5秒优化到1秒,系统飞起来了...
- Xiaomi Interviewer: let's talk about the proficient Registration Center for three days and three nights
- sql sever列名或所提供值的数目与表定义不匹配
- Visual studio vs shortcut key usage
- Interviewer: do you have any plan to request a lot of data that does not exist in redis to destroy the database?
猜你喜欢

AHB2APB桥接器设计(2)——同步桥设计的介绍

Fractional Order PID control

How to write controller layer code gracefully?

Machine learning

2018 mathematical modeling competition - special clothing design for high temperature operation

云服务器配置ftp、企业官网、数据库等方法

面试官:大量请求 Redis 不存在的数据,从而打倒数据库,你有什么方案?

进程终止(你真的学会递归了吗?考验你的递归基础)

Block level elements & inline elements

快速实现单片机和手机蓝牙通信
随机推荐
2022 CISP-PTE(一)文件包含
Compatibility comparison between tidb and MySQL
oracle的similarity方法实现原理
Scala之偏函数Partial Function
Caldera installation and simple use
Centos7.9安装mysql 5.7,并设置开机启动
An Empirical Evaluation of In-Memory Multi-Version Concurrency Control
Yolov6's fast and accurate target detection framework is open source
2018 mathematical modeling competition - special clothing design for high temperature operation
大学数据库mysql
Win10 remote connection to ECS
Nature、science、cell旗下刊物
Instance Tunnel 使用
小米面试官:听你说精通注册中心,我们来聊 3 天 3 夜
Machine learning
win10远程连接云服务器
AHB2APB桥接器设计(2)——同步桥设计的介绍
快速实现蓝牙iBeacn功能详解
Fast implementation of thread mesh networking
An Empirical Evaluation of In-Memory Multi-Version Concurrency Control