当前位置:   article > 正文

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

微信小程序本地生活九宫格图片

一.创建项目

创建新的项目,名称为:本地生活
在这里插入图片描述

二.配置修改json

在app.json中删除其他页面 将index改为grid 自动生成新的文件
添加自己的轮播图片
源代码:

<!--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>

  • 1
  • 2
  • 3
  • 4
  • 5
  • 6
  • 7
  • 8
  • 9
  • 10
  • 11
  • 12
  • 13
  • 14
  • 15
  • 16
  • 17
  • 18
  • 19
  • 20
  • 21

在这里插入图片描述
看不见图片,但是可以看见指示点在动,是因为还未设置图片

三.编写WXML

<!--九宫格区域-->
<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>

  • 1
  • 2
  • 3
  • 4
  • 5
  • 6
  • 7
  • 8
  • 9
  • 10
  • 11
  • 12
  • 13
  • 14
  • 15
  • 16
  • 17
  • 18
  • 19
  • 20
  • 21
  • 22
  • 23
  • 24
  • 25
  • 26
  • 27
  • 28
  • 29
  • 30
  • 31
  • 32
  • 33
  • 34
  • 35
  • 36
  • 37
  • 38
  • 39
  • 40
  • 41
  • 42
  • 43
  • 44
  • 45

预览效果,图片还未规则
在这里插入图片描述
设置WXSS,让轮播图照片显现出来

四.编写WXSS

/* 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;
}
  • 1
  • 2
  • 3
  • 4
  • 5
  • 6
  • 7
  • 8
  • 9
  • 10
  • 11
  • 12
  • 13
  • 14
  • 15
  • 16
  • 17
  • 18
  • 19
  • 20
  • 21
  • 22
  • 23
  • 24
  • 25
  • 26
  • 27
  • 28
  • 29
  • 30
  • 31
  • 32
  • 33
  • 34
  • 35
  • 36
  • 37
  • 38
  • 39
  • 40
  • 41
  • 42
  • 43
  • 44
  • 45

五.最终效果

在这里插入图片描述

声明:本文内容由网友自发贡献,不代表【wpsshop博客】立场,版权归原作者所有,本站不承担相应法律责任。如您发现有侵权的内容,请联系我们。转载请注明出处:https://www.wpsshop.cn/w/小舞很执着/article/detail/775207
推荐阅读
相关标签
  

闽ICP备14008679号