判断、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()
})
相关推荐
IT、木易7 分钟前
ES6 新特性,优势和用法?
前端·ecmascript·es6
粉032121 分钟前
Keeppalived 实现Nginx 的高可用集群
java·服务器·nginx
is今夕22 分钟前
postcss.config.js 动态配置基准值
javascript·vue.js·postcss
青茶绿梅*225 分钟前
500字理透react的hook闭包问题
javascript·react.js·ecmascript
计算机软件程序设计30 分钟前
vue和微信小程序处理markdown格式数据
前端·vue.js·微信小程序
指尖时光.31 分钟前
【前端进阶】01 重识HTML,掌握页面基本结构和加载过程
前端·html
前端御书房34 分钟前
Pinia 3.0 正式发布:全面拥抱 Vue 3 生态,升级指南与实战教程
前端·javascript·vue.js
路在脚下@38 分钟前
Java使用Redisson实现布隆过滤器
java·spring boot
NoneCoder1 小时前
JavaScript系列(84)--前端工程化概述
前端·javascript·状态模式
魔道不误砍柴功1 小时前
Java中的Stream API:从入门到实战
java·windows·python