uni-app 使用九宫格(uni-grid)布局组件

1、运行环境

开发工具为 HBuilder X 4.23, 操作系统为 Windows 11。Vue.js 版本为 3.

2、操作步骤

首先,登录 HBuilder X。然后用桌面浏览器,访问官网组件网址。

https://ext.dcloud.net.cn/plugin?name=uni-grid

在组件网址右上角、点击"下载插件并导入 Hbuilder X"。

此时网址有可能提示再次登录 HBuilder X 账号。完成登录后、在浏览器弹窗点击"打开 HBuilder X"。

此时 HBuilder X 会弹窗供选择将该组件导入到哪个项目。完成选择并确认后、下方的控制台会输出内容、此时便是完成组件注册。

3、代码示例

我们的代码在一个 .vue 文件中,以 menu.vue 为例。

javascript 复制代码
<template>
	<view class="warp">
		<!-- 宫格 -->
		<view class="example-body">
			<uni-grid :column="3" :highlight="true" @change="onClickChange">
				<uni-grid-item :index="i" :key="i" v-for="(menuStub,i) in gridList">
					<view class="grid-item-box" style="background-color: #fff;">
						<!-- <image :src="'/static/grid/c'+(i+1)+'.png'" class="image" mode="aspectFill" /> -->
						<!--text class="big-number">{{i+1}}</text-->
						<text class="text">{{menuStub.mName}}</text>
					</view>
				</uni-grid-item>
			</uni-grid>
		</view>	
	</view>
</template>

<script>
	export default {
		data() {
			return {
				// 固定的菜单示例
				gridList: [{mName:'点检填报'},{mName:'保养填报'},{mName:'点检记录'},{mName:'保养记录'},{mName:'e'},{mName:'f'}]
			}
		},
		methods: {
			onClickChange(e){
				console.log("点击的位置为:",e.detail.index);
				//begin 判断跳转
				
				//end 判断跳转
			}
		}
	}
</script>

<style>
	page {
		display: flex;
		flex-direction: column;
		box-sizing: border-box;
		background-color: #fff;
		min-height: 100%;
		height: auto;
	}
	view {
		font-size: 14px;
		line-height: inherit;
	}
	.example-body {
		display: flex;
		flex-direction: row;
		flex-wrap: wrap;
		justify-content: center;
		padding: 0;
		font-size: 14px;
		background-color: #ffffff;
		flex-wrap: wrap; /* add 240813 */
	}
	
	.section-box{
		display: flex;
		flex-direction: row;
		align-items: center;
		padding: 20rpx;
	}
	.decoration{
		width: 4px;
		height: 12px;
		border-radius: 10px;
		background-color: #2979ff;
	}
	.section-text{
		color: #333;
		margin-left: 15rpx;
	}

	.warp {
		background-color: #fff;
	}

	.example-body {
		flex-direction: column;
		padding: 15px;
		background-color: #ffffff;
	}

	.image {
		width: 50rpx;
		height: 50rpx;
	}
	
	.big-number{
		font-size: 50rpx;
		font-weight: 700;
		font-stretch: condensed;
		font-style:oblique;
	}
	
	.text {
		text-align: center;
		font-size: 26rpx;
		margin-top: 10rpx;
	}

	.example-body {
		display: block;
	}

	.grid-item-box {
		flex: 1;
		display: flex;
		flex-direction: column;
		align-items: center;
		justify-content: center;
		padding: 15px 0;
	}
	
	.grid-item-box-row {
		flex: 1;
		flex-direction: row;
		align-items: center;
		justify-content: center;
		padding: 15px 0;
	}

	.banner-image {
		width: 750rpx;
		height: 400rpx;
	}

	.swiper-box {
		height: 400rpx;
	}

	.search-icons {
		padding: 16rpx;
	}

	.search-container-bar {
		display: flex;
		flex-direction: row;
		justify-content: center;
		align-items: center;
		position: fixed;
		left: 0;
		right: 0;
		z-index: 10;
		background-color: #fff;
	}

	::v-deep
	.uni-searchbar__box {
		border-width: 0;
	}

	::v-deep
	.uni-input-placeholder {
		font-size: 28rpx;
	}
</style>

4、总结

记得先在 HBuilder X 导入组件、再开始开发。(完)

相关推荐
只睡四小时5 天前
Canvas 弹道联机实战:700 行 + 固定时间步长
python·websocket·html5·游戏开发·canvas
码兄科技6 天前
24小时自助健身房系统软件开发实战指南:功能设计与部署方案
java·spring boot·uni-app
2501_916007476 天前
苹果商店iOS应用上架费用全面解析:开发者计划与审核费用计算
android·ios·小程序·https·uni-app·iphone·webview
2501_916008896 天前
如何实现iOS App代码混淆:SwiftShield使用指南
android·ios·小程序·https·uni-app·iphone·webview
zihan5186 天前
自己做软件日记9/21 得到了一个良好的文件结构框架
后端·flutter·前端框架·android studio
慧一居士6 天前
Nuxt 框架 插件plugins功能介绍和使用示例
前端框架
2501_916008896 天前
怎么用 Godot 导出 iOS 应用并上架 App Store?签名字段该填什么?
android·ios·小程序·https·uni-app·iphone·webview
郑州光合科技余经理6 天前
同城外卖小程序开发:下单成功后,后台导出能不能对上用户端状态
开发语言·前端·git·后端·uni-app·php·ai编程
我命由我123456 天前
CSS - CSS 媒体查询 orientation
前端·javascript·css·html·css3·html5·js
志尊宝6 天前
Vue3 零基础每日笔记(048):嵌套路由与命名视图——后台管理系统布局雏形
前端·javascript·vue.js·笔记·html5