WeChat の柔軟なレイアウトを理解する - 簡単にページを作成する

フレックス レイアウトの概要

ボックスモデルに基づくレイアウトの従来のソリューションは、display 属性 + position 属性 + float 属性に依存しています。

フレックスレイアウトとは?

  1. Flex は Flexible Box の略で、ボックス モデルに最大限の柔軟性を提供するために使用される「柔軟なレイアウト」を意味します。

  1. 任意のコンテナーをフレックス レイアウトとして指定できます。

  1. 表示: 'フレックス'

コンテナには、デフォルトで水平主軸と垂直交差軸の 2 つの軸があります。主軸の開始位置(境界線との交点)を主始点、終点を主終点、横軸の始点を交点始点、終点を交点点と呼びます。

デフォルトでは、アイテムは主軸に沿って配置されます。1つのアイテムが占める主軸のスペースをメインサイズ、1つのアイテムが占める横軸のスペースをクロスサイズと呼びます。

フレックス プロパティ

  • フレックス方向

主軸のデフォルトの方向は行です

  • flex-wrap 軸線が収まらない場合にラインを折り返す方法

  • flex-flow は、flex-direction および flex-wrap プロパティの省略形です。

  • 正当化コンテンツ

主軸上の項目の配置を定義します

  • 整列項目

交差軸上でアイテムを整列する方法を定義します

  • align-content 属性は、複数の軸の配置を定義します

フレックス レイアウトが設定されると、子要素の float、clear、および vertical-align プロパティは無効になることに注意してください。

学習アドレス:

http://www.runoob.com/w3cnote/flex-grammar.html

会議OAプロジェクト-ホーム

序文

  1. アプレットには DOM オブジェクトがなく、すべてがコンポーネント化に基づいています

  1. 予備知識

  1. イベントの仕組みを理解する

  1. コンポーネント化を理解する

  1. データバインディングを理解する

  1. フレックス レイアウト

  1. モバイル適応ソリューション

  1. 思慮深いヒント

Vueを学んだ後、小さなプログラムを開発する方が簡単です

目標

構成

  • config/api.js

// 以下是业务服务器API地址
 // 本机开发API地址
var WxApiRoot = 'http://localhost:8080/demo/wx/';
// 测试环境部署api地址
// var WxApiRoot = 'http://192.168.0.101:8070/demo/wx/';
// 线上平台api地址
//var WxApiRoot = 'https://www.oa-mini.com/demo/wx/';
​
module.exports = {
  IndexUrl: WxApiRoot + 'home/index', //首页数据接口
  SwiperImgs: WxApiRoot+'swiperImgs', //轮播图
  MettingInfos: WxApiRoot+'meeting/list', //会议信息
};

承知しました

  • app.json

"list": [{
      "pagePath": "pages/index/index",
      "text": "首页",
      "iconPath": "/static/tabBar/coding.png",
      "selectedIconPath": "/static/tabBar/coding-active.png"
    },
      {
        "pagePath": "pages/meeting/list/list",
        "iconPath": "/static/tabBar/sdk.png",
        "selectedIconPath": "/static/tabBar/sdk-active.png",
        "text": "会议"
      },
      {
        "pagePath": "pages/vote/list/list",
        "iconPath": "/static/tabBar/template.png",
        "selectedIconPath": "/static/tabBar/template-active.png",
        "text": "投票"
      },
      {
        "pagePath": "pages/ucenter/index/index",
        "iconPath": "/static/tabBar/component.png",
        "selectedIconPath": "/static/tabBar/component-active.png",
        "text": "设置"
      }]

モックツール

  • imageSrcs 画像データ

{
  "data": {
    "images":[
  {
    "img": "https://cdn-we-retail.ym.tencent.com/tsr/home/v2/banner1.png",
    "text": "1"
  },
  {
    "img": "https://cdn-we-retail.ym.tencent.com/tsr/home/v2/banner2.png",
    "text": "2"
  },
  {
    "img": "https://cdn-we-retail.ym.tencent.com/tsr/home/v2/banner3.png",
    "text": "3"
  },
  {
    "img": "https://cdn-we-retail.ym.tencent.com/tsr/home/v2/banner4.png",
    "text": "4"
  },
  {
    "img": "https://cdn-we-retail.ym.tencent.com/tsr/home/v2/banner5.png",
    "text": "5"
  },
  {
    "img": "https://cdn-we-retail.ym.tencent.com/tsr/home/v2/banner6.png",
    "text": "6"
  }
]
  },
  "statusCode": "200",
  "header": {
    "content-type":"applicaiton/json;charset=utf-8"
  }
}

仮想データをデフォルト設定する WeChat 開発者ツールに付属のモック

ページ

  • index.css

page{
    height: 100%;
    background-color: #efeff4;
}

スワイプ

  • index.wxml

<view>
    <swiper autoplay="true" indicator-dots="true" indicator-color="#fff" indicator-active-color="#00f">
        <block wx:for="{
    
    {imgSrcs}}" wx:key="text">
            <swiper-item>
                <view>
                    <image src="{
    
    {item.img}}" class="swiper-item" />
                </view>
            </swiper-item>
        </block>
    </swiper>
</view>
  • index.css

.swiper-item {
    height: 300rpx;
    width: 100%;
    border-radius: 10rpx;
}
  • index.js

 const api = require("../../config/api")
 
 loadSwiperImgs(){
    let that=this;
    wx.request({
        url: api.SwiperImgs,
        dataType: 'json',
        success(res) {
          console.log(res)
          that.setData({
              imgSrcs:res.data.images
          })
        }
      })
  }

ページ読み込み関数で load data メソッドを呼び出す

会議情報

  • モックデータ

{
  "data": {
    "lists": [
        {
          "id": "1",
          "image": "/static/persons/1.jpg",
          "title": "对话产品总监 | 深圳·北京PM大会 【深度对话小米/京东/等产品总监】",
          "num":"304",
          "state":"进行中",
          "starttime": "2022-03-13 00:00:00",
          "location": "深圳市·南山区"
        },
        {
          "id": "1",
          "image": "/static/persons/2.jpg",
          "title": "AI WORLD 2016世界人工智能大会",
          "num":"380",
          "state":"已结束",
          "starttime": "2022-03-15 00:00:00",
          "location": "北京市·朝阳区"
        },
        {
          "id": "1",
          "image": "/static/persons/3.jpg",
          "title": "H100太空商业大会",
          "num":"500",
          "state":"进行中",
          "starttime": "2022-03-13 00:00:00",
          "location": "大连市"
        },
        {
          "id": "1",
          "image": "/static/persons/4.jpg",
          "title": "报名年度盛事,大咖云集!2016凤凰国际论坛邀您“与世界对话”",
          "num":"150",
          "state":"已结束",
          "starttime": "2022-03-13 00:00:00",
          "location": "北京市·朝阳区"
        },
        {
          "id": "1",
          "image": "/static/persons/5.jpg",
          "title": "新质生活 · 品质时代 2016消费升级创新大会",
          "num":"217",
          "state":"进行中",
          "starttime": "2022-03-13 00:00:00",
          "location": "北京市·朝阳区"
        }
      ]
  },
  "statusCode": "200",
  "header": {
    "content-type":"applicaiton/json;charset=utf-8"
  }
}
  • index.wxml

<view class="mobi-title">
    <text class="mobi-icon"></text>
    <text>会议信息</text>
</view>
<block wx:for-items="{
    
    {lists}}" wx:for-item="item" wx:key="item.id">
    <view class="list" data-id="{
    
    {item.id}}">
        <view class="list-img">
            <image class="video-img" mode="scaleToFill" src="{
    
    {item.image}}"></image>
        </view>
        <view class="list-detail">
            <view class="list-title"><text>{
    
    {item.title}}</text></view>
            <view class="list-tag">
                <view class="state">{
    
    {item.state}}</view>
                <view class="join"><text class="list-num">{
    
    {item.num}}</text>人报名</view>
            </view>
            <view class="list-info"><text>{
    
    {item.location}}</text>|<text>{
    
    {item.starttime}}</text></view>
        </view>
    </view>
</block>
<view class="section bottom-line">
    <text>到底啦</text>
</view>
  • index.js

loadMeetingInfos(){
    let that=this;
    wx.request({
        url: api.MettingInfos,
        dataType: 'json',
        success(res) {
          console.log(res)
          that.setData({
              lists:res.data.lists
          })
        }
      })
  }
  • index.wxss

page{
  height: 100%;
  background-color: #efeff4;
}
.swiper-item{
  height: 300rpx;
  width: 100%;
  border-radius: 10rpx;
}
.mobi-title{
  display: flex;
  align-items: center;
}
.mobi-icon{
  display:inline-block;
  width: 2px;
  height: 20px;
  margin: 2px 6px;
  background-color: red;
}
.mobi-title text{
  font-weight: 800;
  color: #4e4949;
}
.list{
 display: flex;
 flex-direction: row;
 border-top: 1px solid #eeeeee;
 width: 100%;
 height: 120px;
 align-items: center;
 margin-top: 10rpx;
 background-color: #fff;
 padding: 0 20rpx 0 0;
}
.list-img,.video-img{
  width: 75px;
  height: 75px;
}
.list-img{
}
.video-img{
}
.list-detail{
margin: 0 0 0 10px;
}
.list-title{
 font-weight: 700;
}
.list-tag{
  display: flex;
  margin: 5px 0 10px 0;
  align-items: center;
  color: lightgray;
}
.state{
 border: 1px solid lightblue;
 padding: 1px 10px;
 color: lightblue;

}
.join{
  margin: 0 0 0 10px;
}
.list-num{
  color: red;
}
.list-info{
 color: lightgray;
 font-size: 14px;
}
.bottom-line{
  display: flex;
  height: 60rpx;
  justify-content: center;
  align-items: center;
  background-color: #f3f3f3;
}
.bottom-line text{
  font-size: 9pt;
  color: #666;
}

おすすめ

転載: blog.csdn.net/qq_62898618/article/details/128552884