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


    一.创建项目

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

    二.配置修改json

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

    
    
    <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

    五.最终效果

    在这里插入图片描述

  • 相关阅读:
    2023品牌新媒体矩阵营销洞察报告:流量内卷下,如何寻找增长新引擎?
    【Java基础篇】第八章 认识面向对象
    《Vue.js实战》8.1自定义指令答案
    iai 定向 题解
    RIP路由配置
    把握鸿蒙生态机遇,共创智能应用未来
    RabbitMQ
    顺序表合并
    nginx的location的优先级和匹配方式和重定向
    Effective C++ 阅读笔记 06:继承与面向对象设计(上)
  • 原文地址:https://blog.csdn.net/qq_62512326/article/details/133693346