快速实现宫格菜单按钮组件,提供常见的宫格布局,如八宫格、九宫格的菜单组件; 下载完整代码请访问uni-app插件市场地址:https://ext.dcloud.net.cn/plugin?id=12592
效果图如下:
参考代码如下:
# 宫格菜单按钮组件,提供常见的宫格布局,如八宫格、九宫格
#### HTML代码部分
```html
<template>
<view class="content">
<view class="headLine"> 八宫格 </view>
<view class="upView" style="background-color: aliceblue;">
<!--使用方法: click:事件 myFlag:标识 myText:文字 imgSrc:图片地址 size:图片尺寸 -->
<CCMenuBtn @click="menuClick(0)" myFlag="12" myText='功能1' imgSrc='../../static/jsl_zhpj.png'></CCMenuBtn>
<CCMenuBtn @click="menuClick(1)" myText='功能2' imgSrc='../../static/jsl_jsl.png'></CCMenuBtn>
<CCMenuBtn @click="menuClick(2)" myText='功能3' imgSrc='../../static/jsl_zjl.png'></CCMenuBtn>
<CCMenuBtn myText='功能4' imgSrc='../../static/jsl_xxl.png'></CCMenuBtn>
<CCMenuBtn myText='功能5' imgSrc='../../static/jsl_wl.png'></CCMenuBtn>
<CCMenuBtn myText='功能6' imgSrc='../../static/jsl_nll.png'></CCMenuBtn>
<CCMenuBtn myText='功能7' imgSrc='../../static/jsl_cxjq.png'></CCMenuBtn>
<CCMenuBtn myFlag="2" myText='功能8' imgSrc='../../static/jsl_jcxx.png'></CCMenuBtn>
</view>
<view class="headLine"> 九宫格 </view>
<!-- 九宫格菜单区 -->
<view class="upView" style="background-color: antiquewhite;">
<CCMenuBtn class="nineV" myText='菜单1' imgSrc='../../static/jsl_zhpj.png'></CCMenuBtn>
<CCMenuBtn class="nineV" myText='菜单2' imgSrc='../../static/jsl_jsl.png'></CCMenuBtn>
<CCMenuBtn class="nineV" myText='菜单13' imgSrc='../../static/jsl_zjl.png'></CCMenuBtn>
<CCMenuBtn class="nineV" myText='菜单14' imgSrc='../../static/jsl_xxl.png'></CCMenuBtn>
<CCMenuBtn class="nineV" myText='菜单15' imgSrc='../../static/jsl_wl.png'></CCMenuBtn>
<CCMenuBtn class="nineV" myText='菜单16' imgSrc='../../static/jsl_nll.png'></CCMenuBtn>
<CCMenuBtn class="nineV" myText='菜单17' imgSrc='../../static/jsl_cxjq.png'></CCMenuBtn>
<CCMenuBtn class="nineV" myFlag="2" myText='菜单18' imgSrc='../../static/jsl_jcxx.png'></CCMenuBtn>
<CCMenuBtn class="nineV" myFlag="2" myText='菜单18' imgSrc='../../static/jsl_jcxx.png'></CCMenuBtn>
</view>
</view>
</template>
```
#### JS代码 (引入组件 填充数据)
```javascript
<script>
import CCMenuBtn from "../../components/CCMenuBtn.vue"
export default {
components: {
CCMenuBtn
},
data() {
return {
title: 'Hello'
}
},
onLoad() {
},
methods: {
menuClick(menuName) {
console.log("点击菜单 = " + menuName)
}
}
}
</script>
```
#### CSS
```CSS
<style>
.content {
display: flex;
flex-direction: column;
}
.upView {
display: flex;
flex-direction: row;
flex-wrap: wrap;
margin-left: 12px;
width: calc(100vw - 24px);
margin-top: 10px;
padding: 4px 0px;
background-color: white;
}
.headLine {
height: 30px;
line-height: 30px;
margin: 10px 15px;
font-size: 20px;
}
.nineV {
width: calc((100vw - 24px)/3);
}
</style>
```
网友评论