• 小程序--公共组件


    tab组件为例

    1.在项目下建一个components(组件)的文件夹

     2.新建组件文件夹 生成同名page

    3.代码片段

    tab.json
    {
      "component": true,
      "usingComponents": {}
    }
    tab.js
    //跳转到首页
      gohome(){
        wx.switchTab({
          url: '../../pages/home/home'
        })
      },
    
      //跳转到订单页
      goorder(){
        wx.switchTab({
          url: '../../pages/mine/mine'
        })
      }
    tab.wxml
    <view class="tabbar">
        <view class="home icon" bindtap="gohome">
          <image src="http://47.103.128.16:9004/busiroom/theme/default/images/minApp/img/home2.png" class="image"></image>
          <view class="text">首页</view>
        </view>
        <view class="order icon" bindtap="goorder">
          <image src="http://47.103.128.16:9004/busiroom/theme/default/images/minApp/img/mine2.png" class="image"></image>
          <view class="text">我的</view>
        </view>
    </view>
    tab.wxss
    .tabbar{
      width: 100%;
      display: flex;
      flex-direction: row;
      justify-content: space-between;
      height: 95rpx;
      position: fixed;
      bottom: 0;
      background-color: #fff;
      padding: 10rpx 0 0 0;
      box-sizing: border-box;
    }
    .tabbar .icon{
      width: 50%;
      height: 100%;
      text-align: center;
      display: flex;
      flex-direction: column;
      align-items: center;
    }
    .tabbar .icon .image{
      width: 55rpx;
      height: 55rpx;
    }
    .tabbar .text{
      color: #7F8389;
      font-size: 20rpx;
      line-height: 35rpx;
    }

    4.在其他页面使用公共组件

    wxml
    直接使用创建的page页的命名为标签
    <tab></tab>
    json
    //引入公共组件的路径 不需要后缀名
    {
      "usingComponents": {
        "tab":"../../components/tab/tab"
      }
    }

     5.展示

  • 相关阅读:
    经典回溯问题--八皇后dfs递归回溯求解【DFS】
    CSP认证考试(第九次)第一题
    C++字符串和数字格式转化(使用sprintf()和sscanf()函数)
    2016蓝桥杯C++A组第六题 寒假作业【暴力搜索】
    先序非递归建立二叉树
    sqlsrv数据库复杂语句1
    tp5域名配置
    JavaScript使用 value 属性
    数据库随机查询6条数据
    文件目录问题
  • 原文地址:https://www.cnblogs.com/qinlinkun/p/12881484.html
Copyright © 2020-2023  润新知