微信小程序之本地生活(九宫格)

文章目录

一.创建项目

创建新的项目,名称为:本地生活

二.配置修改json

在app.json中删除其他页面 将index改为grid 自动生成新的文件

添加自己的轮播图片

源代码:

html 复制代码
<!--pages/grid/grid.wxml-->
<!--轮播图区域-->
<swiper indicator-dots="true" indicator-color="blue"
indicator-active-color="red" autoplay="true" circular="true" interval="3000">
<swiper-item>
<view class="item">
<image src="/images/111.jpg" mode="aspectFill" style="width: 100%; height:100%" />
</view>
</swiper-item>
<swiper-item>
<view class="item">
<image src="/images/222.jpg" mode="aspectFill" style="width: 100%; height:100%" />
</view>
</swiper-item>
<swiper-item>
<view class="item">
<image src="/images/333.jpg" mode="aspectFill" style="width: 100%; height:100%" />
</view>
</swiper-item>
</swiper>

看不见图片,但是可以看见指示点在动,是因为还未设置图片

三.编写WXML

html 复制代码
<!--九宫格区域-->
<view class="grids">
<view class="grid-item">
<image src="/images/food.png"/>
<text>美食</text>
</view>
<view class="grid-item">
<image src="/images/fitup.png"/>
<text>装修</text>
</view>

<view class="grid-item">
<image src="/images/bath.png"/>
<text>洗浴</text>
</view>

<view class="grid-item">
<image src="/images/car.png"/>
<text>汽车</text>
</view>
<view class="grid-item">
<image src="/images/sing.png"/>
<text>唱歌</text>
</view>

<view class="grid-item">
<image src="/images/house.png"/>
<text>住宿</text>
</view>

<view class="grid-item">
<image src="/images/study.png"/>
<text>学习</text>
</view>
<view class="grid-item">
<image src="/images/work.png"/>
<text>工作</text>
</view>

<view class="grid-item">
<image src="/images/marry.png"/>
<text>结婚</text>
</view>
</view>

预览效果,图片还未规则

设置WXSS,让轮播图照片显现出来

四.编写WXSS

html 复制代码
/* pages/grid/grid.wxss */

.item{
  width: 100%;
  height: 100%;
}
.grids{
  display: flex;
  flex-wrap: wrap;/*自动绕行*/
}

.grids .grid-item{
  width: 250rpx; /*750÷3 =250*/
  height: 250rpx;
  border-right: 1rpx solid #eee;
  border-bottom: 1rpx solid #eee;
  display: flex;
  flex-direction: column;
  justify-content: center;
  align-items: center;
}
/*清除第3个格子的右边框*/
.grids .grid-item:nth-child(3){
  border-right:0;
}
/*清除第6个格子的右边框*/
.grids .grid-item:nth-child(6){
  border-right:0;
}
/*清除第9个格子的右边框*/
.grids .grid-item:nth-child(9){
  border-right:0;
}
/*每个格子内的图片样式*/
.grids .grid-item image{
  width: 90rpx;
  height: 90rpx;
}

/*每个格子内的文本样式*/
.grids .grid-item text{
  color: #999;
  font-size: 35rpx;
  margin-top: 20rpx;
}

五.最终效果

相关推荐
API技术员28 分钟前
item_get_app - 根据ID取商品详情原数据H5数据接口实战解析
javascript
八哥程序员29 分钟前
Chrome DevTools 详解系列之 Elements面板
javascript·浏览器
coderHing[专注前端]33 分钟前
告别 try/catch 地狱:用三元组重新定义 JavaScript 错误处理
开发语言·前端·javascript·react.js·前端框架·ecmascript
汝生淮南吾在北1 小时前
SpringBoot3+Vue3小区物业报修系统+微信小程序
微信小程序·小程序·vue·毕业设计·springboot·课程设计·毕设
UIUV1 小时前
JavaScript中this指向机制与异步回调解决方案详解
前端·javascript·代码规范
momo1001 小时前
IndexedDB 实战:封装一个通用工具类,搞定所有本地存储需求
前端·javascript
静待雨落1 小时前
如何在Taro项目中使用axios
微信小程序·taro
San301 小时前
从零到一:彻底搞定面试高频算法——“列表转树”与“爬楼梯”全解析
javascript·算法·面试
WLJT1231231231 小时前
AI懂你,家更暖:重塑生活温度的智能家电新范式
人工智能·生活
JellyDDD1 小时前
h5上传大文件可能会导致手机浏览器卡死,重新刷新的问题
javascript·上传文件