学习打卡04 小程序03

lyqiuyo 2021-12-05 16:30:32

一、flex布局

{
  "pages":[
    "pages/index/index"
  ],
  "window":{
    "navigationBarBackgroundColor": "#000000",   //黑色
    "navigationBarTitleText": "发现"       //导航标题
  },
  "sitemapLocation": "sitemap.json"    //配置其小程序页面是否允许为微信索引
}
​
<!--index.wxml-->
<view class = "container">
  <view class="listGroup" wx:for="{{list}}" wx:for-item="value" wx:key="value{{index}}">
    <view class="listItem" wx:for="{{value}}" wx:for-item="value1" wx:key="value{{index}}">
    <image src="{{value1.icon}}"></image>
    <text>{{value1.text}}</text>
    <image></image>
    </view>
  </view>
</view>
/**index.wxss**/
​
.container{
  height: 100vh;                       //100视窗
  background-color: silver;            //背景色 银色
  display: flex;                       //flex布局
  flex-direction: column;              //垂直布局
}
​
.listGroup{
  background-color: white;              
  margin: 20rpx 0;                   //元素边缘 上下外边距20rpx 左右距离为0
}
​
.listItem{
  display: flex;
  flex-direction: row;
  align-items: center;
  border: 1rpx solid silver;
  padding: 10rpx;
}
​
image{
  width: 80rpx;
  height: 80rpx;
  margin: 0 15rpx;
}

二、循环创建栏目

// index.js
Page({
​
  /**
   * 页面的初始数据
   */
  data: {
    list: [
      [
        {text:'朋友圈',icon:''}
      ],
      [
        {text:'扫一扫',icon:''},
        {text:'摇一摇',icon:''}
      ],
      [
        {text:'搜一搜',icon:''},
        {text:'搜一搜',icon:''}
      ],
      [
        {text:'购物',icon:''},
        {text:'游戏',icon:''}
      ],
      [
        {text:'小程序',icon:''}
      ],
    ]
  }
})

wxml中绑定循环,用 wx:for, wx:for-item 取别名, wx:key 当前的key值,{{index}}表示当前的索引值

...全文
125 回复 打赏 收藏 转发到动态 举报
AI 作业
写回复
用AI写文章
回复
切换为时间正序
请发表友善的回复…
发表回复

67,943

社区成员

发帖
与我相关
我的任务
社区描述
灌水发信息每周送书 灌水发干货每周送惊喜 谁最水过年送大礼 谁最硬核过年送大礼 谁最贡献过年送大礼
社区管理员
  • 1_bit
加入社区
  • 近7日
  • 近30日
  • 至今
社区公告

我们“新手村”社区就是大家的孵化器

你们学习,我来评分

每周最高分送一本书

每月第四周送一份机械键盘

咱们新手村使用一切狂暴手段让优秀的人得到奖励

 

试试用AI创作助手写篇文章吧