【uni app 通过 v-if 实现视图切换】

uni app 通过 v-if 实现视图切换
uniapp视图切换

<template>
	<view>
		<button type="primary" @click="toggleComponent">
			视图切换
		</button>
		<!-- 列表模式_自写代码 -->
		<view v-if="showComponent">
			<view class="uni-list-ListPattern">
				<view class="uni-list-item-margin" v-for="i in data" :key="i.FID">
					<view style="display: flex; justify-content: space-between;">
						<view style="width: 20%; height: 100px;">
							<image style="width: 100%; height: 100%;" src="../../static/meinv01.png" mode="aspectFit">
							</image>
						</view>
						<view class="uni-list-item-text" style="width: 80%;">
							<text>ID:{{i.Id}}</text>
							<text>编码:{{i.Number}}</text>
							<text>名称:{{i.Name}}</text>
							<text>数量:{{i.Qty}}</text>
						</view>
					</view>
				</view>
			</view>
		</view>
		<!-- 宫格模式_自写代码 -->
		<view v-if="!showComponent">
			<view class="uni-list-PalaceGrid">
				<view class="uni-list-item-PalaceGrid" v-for="i in data" :key="i.FID">
					<view class="uni-list-item-margin">
						<view>
							<image class="img-attribute" src="../../static/meinv01.png" mode="aspectFit"></image>
						</view>
						<view class="uni-list-item-text">
							<text>ID:{{i.Id}}</text>
							<text>编码:{{i.Number}}</text>
							<text>名称:{{i.Name}}</text>
							<text>数量:{{i.Qty}}</text>
						</view>
					</view>
				</view>
			</view>
		</view>
	</view>
</template>

<script>
	export default {
		data() {
			return {

				data: [{
						"Id": 10001,
						"Number": "WL00001",
						"Name": "箱体A",
						"SpecsModel": "304不锈钢,100*50,板厚T=1.0",
						"Qty": 2,
					},
					{
						"Id": 10002,
						"Number": "WL00002",
						"Name": "箱体A",
						"SpecsModel": "304不锈钢,100*100,板厚T=1.0",
						"Qty": 5,
					},
					{
						"Id": 10003,
						"Number": "WL00003",
						"Name": "箱体B",
						"SpecsModel": "镀锌板,100*300,板厚T=1.0",
						"Qty": 4,
					}
				],
				showComponent: true, // 控制组件显示状态的变量
			}
		},
		// mounted功能为页面挂载的时候自动触发
		mounted() {
			//console.log(this.data)
		},
		methods: {
			toggleComponent() {
				this.showComponent = !this.showComponent; // 切换列表/宫格组件显示状态
			}
		}
	}
</script>
  • 5
    点赞
  • 5
    收藏
    觉得还不错? 一键收藏
  • 0
    评论
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值