当前位置:网站首页>Use uview to enable tabbar to display the corresponding number of tabbars according to permissions
Use uview to enable tabbar to display the corresponding number of tabbars according to permissions
2022-06-27 07:18:00 【Talking characters】
adopt uview Give Way tabbar Display the corresponding number of tabbar
finish building uview-app Shelves
Normal configuration page.json Of tabbar term
After the configuration is completed, pass vuex To control tabbar list The change of
The path in the above configuration must be preceded by /
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": " home page ",
"midButton": false,
}, {
"pagePath": "/pages/center/index",
"iconPath": "/static/center.png",
"selectedIconPath": "/static/center-selected.png",
"text": " I ",
"midButton": false,
},{
"pagePath": "/pages/perms/perms",
"iconPath": "/static/center.png",
"selectedIconPath": "/static/center-selected.png",
"text": " Permission page ",
"midButton": false,
}]
const store=new Vuex.Store({
state:{
tabbar_readonly:tabbar,
tabbar:tabbar
},
mutations:{
$uStore(state, payload) {
// Determine whether to call at multiple levels ,state The existence of objects in , Such as 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 {
// Single level variable , stay state It's just the case of an ordinary variable
state[payload.name] = payload.value;
saveKey = payload.name;
}
}
}
})
export default store
$u.mixin.js
import {
mapState
} from 'vuex'
import store from "@/store"
// Try to put the user's... In the root directory store/index.js Of vuex Of state Variable , Load all into global variables
let $uStoreKey = [];
try {
$uStoreKey = store.state ? Object.keys(store.state) : [];
} catch (e) {}
module.exports = {
created() {
// take vuex The method is hung to $u in
// Usage method: : If you want to modify vuex Of state Medium user.name Variable is " epic " => this.$u.vuex('user.name', ' epic ')
// If you want to modify vuex Of state Of version Variable is 1.0.1 => this.$u.vuex('version', '1.0.1')
this.$u.vuex = (name, value) => {
this.$store.commit('$uStore', {
name,
value
})
}
},
computed: {
// take vuex Of state All variables in , Deconstruction to global blending mixin in
...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()
At every tabbar Used in pages u-tabbar Components
because vuex Medium state.tabbar It has been infiltrated globally , So each tabbar The page already has this.tabbar This variable .
In the component's list Attribute into tabbar Just go
边栏推荐
猜你喜欢

Modeling competition - optical transport network modeling and value evaluation

Win10 remote connection to ECS

正斜杠反斜杠的由来

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

Fast realization of Bluetooth communication between MCU and mobile phone

On gpu: historical development and structure

Cloud-Native Database Systems at Alibaba: Opportunities and Challenges

thrift

Currying Scala functions

从5秒优化到1秒,系统飞起来了...
随机推荐
一個人管理1000臺服務器?這款自動化運維工具一定要掌握
Get the query parameter in the address URL specify the parameter method
获取地址url中的query参数指定参数方法
Fast implementation of thread mesh networking
View functions in tidb
一个人管理1000台服务器?这款自动化运维工具一定要掌握
Spark SQL common time functions
Tidb basic functions
The interviewer of a large front-line factory asked: do you really understand e-commerce order development?
专业四第二周自测
Transaction overview of tidb
(已解决) npm突然报错 Cannot find module ‘D:\Program Files\nodejs\node_modules\npm\bin\npm-cli.js‘
2022 cisp-pte (I) document contains
Vs how to configure opencv? 2022vs configuration opencv details (multiple pictures)
Basic SQL operations in tidb
multiprocessing. Detailed explanation of pool
面试官:用分库分表如何做到永不迁移数据和避免热点问题?
(已解决) MINet 进行测试时报错如下 raise NotImplementedError
Delay queue `delayqueue`
On gpu: historical development and structure