判断、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()
})
相关推荐
小磊哥er9 分钟前
【前端工程化】前端工作中的业务规范有哪些
前端
旷世奇才李先生13 分钟前
Next.js 安装使用教程
开发语言·javascript·ecmascript
木头没有瓜14 分钟前
idea离线安装插件
java·ide·intellij-idea
ᥬ 小月亮19 分钟前
webpack基础
前端·webpack
llwszx24 分钟前
Spring中DelayQueue深度解析:从原理到实战(附结构图解析)
java·后端·spring·delayqueue·延迟任务
YongGit38 分钟前
探索 AI + MCP 渲染前端 UI
前端·后端·node.js
述雾学java38 分钟前
Spring Cloud Feign 整合 Sentinel 实现服务降级与熔断保护
java·spring cloud·sentinel
保持学习ing39 分钟前
苍穹外卖day3--公共字段填充+新增菜品
java·阿里云·实战·springboot·前后端·外卖项目·阿里云文件存储
77qqqiqi1 小时前
正则表达式
java·后端·正则表达式
慧一居士1 小时前
<script setup>中的setup作用以及和不带的区别对比
前端