判断、v-if判断显示隐藏,功能区循环案例。

判断条件

1.第一种

如果身份是管理员 , 那么全部显示

如果身份是员工 ,那么除了value等于1的全部都显示

html 复制代码
v-if="( user.state.level ==='admin') || ( user.state.level === 'staff' && item.value !== 1)"
html 复制代码
<view class="funcBox">
	<block v-for="(item,index) in funcList" :key="index">
		<view class="item" @click="toFunc(item)" v-if="( user.state.level ==='admin') || ( user.state.level === 'staff' && item.value !== 1)">
			<image :src="item.img" mode="scaleToFill"></image>
			<view class="funcTxt">{{item.title}}</view>
		</view>
	</block>
</view>

2.根据数据判断

html 复制代码
v-if="item.isShow"
html 复制代码
<view class="funcBox">
	<block v-for="(item,index) in funcList" :key="index">
		<view class="item" @click="toFunc(item)" v-if="item.isShow">
			<image :src="item.img" mode="scaleToFill"></image>
			<view class="funcTxt">{{item.title}}</view>
		</view>
	</block>
</view>
javascript 复制代码
const funcList = ref([{
		value: 1,
		img: '/static/images/index1.png',
		title: '第一个',
		path: '',
		isShow: user.state.level === 'staff' ? false : true
	}, {
		value: 2,
		img: '/static/images/index2.png',
		title: '第二个',
		path: '/pages/index/device/list',
		isShow: true
	}, {
		value: 3,
		img: '/static/images/index3.png',
		title: '第三个',
		path: '',
		isShow: true
	}, {
		value: 4,
		img: '/static/images/index4.png',
		title: '第四个',
		path: '',
		isShow: user.state.level === 'staff' ? false : true
	}])

案例

html 复制代码
<view class="funcBox">
	<block v-for="(item,index) in funcList" :key="index">
		<view class="item" @click="toFunc(item)"
			v-if="( user.state.level ==='admin') || ( user.state.level === 'staff' && item.nothing)">
			<image :src="item.img" mode="scaleToFill"></image>
			<view class="funcTxt">{{item.title}}</view>
		</view>
	</block>
</view>
javascript 复制代码
import {
	commonStore
} from '@/store/commonStore.js'
import {
	userStore
} from '@/store/userStore.js'
const common = commonStore()
const user = userStore()
onShow(() => {
	common.getUserInfo()
})

const funcList = ref([{
	value: 1,
	img: '/static/images/index1.png',
	title: '第1',
	path: '/pages/index/siteManage/siteManage',
	nothing: false,
}, {
	value: 2,
	img: '/static/images/index2.png',
	title: '第2',
	path: '/pages/index/deviceManage/deviceList',
	nothing: true,
}, {
	value: 3,
	img: '/static/images/index3.png',
	title: '第3',
	path: '/pages/index/allRechargeRecord',
	nothing: true,
}, {
	value: 4,
	img: '/static/images/index4.png',
	title: '第4',
	path: '/pages/index/deviceManage/useRecord',
	nothing: true,
}, {
	value: 5,
	img: '/static/images/index5.png',
	title: '第5',
	path: '/pages/index/earnings/earnings',
	nothing: true,
}, {
	value: 6,
	img: '/static/images/index6.png',
	title: '第6',
	path: '/pages/index/storeManage/storeManage',
	nothing: false,
}, {
	value: 7,
	img: '/static/images/index7.png',
	title: '第7',
	path: '/pages/index/deviceManage/deviceActivation',
	nothing: false,
}, {
	value: 8,
	img: '/static/images/index8.png',
	title: '第8',
	path: '/pages/index/masterManage/masterManage',
	nothing: true,
}])
onShow(() => {
	common.getUserInfo()
})
相关推荐
coffee_baby1 分钟前
享元模式详解:解锁高效资源管理的终极武器
java·spring boot·mybatis·享元模式
蓝莓味柯基2 分钟前
React——点击事件函数调用问题
前端·javascript·react.js
资深前端之路3 分钟前
react jsx
前端·react.js·前端框架
爱学习的真真子9 分钟前
菜鸟也能轻松上手的Java环境配置方法
java·开发语言
cc蒲公英16 分钟前
vue2中使用vue-office库预览pdf /docx/excel文件
前端·vue.js
一嘴一个橘子17 分钟前
js 将二进制文件流,下载为excel文件
javascript
Sam902928 分钟前
【Webpack--013】SourceMap源码映射设置
前端·webpack·node.js
曳渔35 分钟前
Java-数据结构-二叉树-习题(三)  ̄へ ̄
java·开发语言·数据结构·算法·链表
shark-chili1 小时前
数据结构与算法-Trie树添加与搜索
java·数据结构·算法·leetcode
白乐天_n1 小时前
FRIDA-JSAPI:Java使用
java·jsapi·frida