• 小程序常用片段


    生命周期:

     

    json文件配置:

    {
        "navigationBarTitleText": "地址管理",
        "enablePullDownRefresh": false,
        "usingComponents": {
          "zan-field": "../../../zanui/field/index"
        }
    }

    微信内置组件:

    ---弹窗:

    wx.showModal({
         title: '提示',
         content: '请填写完整的收货信息',
         showCancel: false
    })

    小程序标签:

    --image:

    <image class="cateImgBg" mode="scaleToFill" src="https://mp.orancat.com/images/static/cate04.jpg">
    <image src="{{shopItem.WXImgUrl}}"></image>

    请求数据    wx.showLoading(        title: '加载中..',

        })
        var self = this;
        var proId = '15318114185722997'
        var pageSrc = 'page/component/dtl/details';
        var scene = proId;
        wx.request({
          url: "https://mp.orancat.com/ouser/createQrcode",
          method: "POST",
    header: {
    "Content-Type": "application/json"
            },
            data: { page: pageSrc, scene: scene,
                   productItem: JSON.stringify(productItem)
            },
          complete: function (res) {
            wx.hideLoading();
            console.log(res, 'createQrcode');
            if (res.data.status == 0) {
                self.setData({
                    qrCodeImgUrl:res.data.imgUrl
                })
            } else {
              wx.showModal({
                title: '提示',
                content: '请求失败,请联系管理员',
                showCancel: false
              })
            }
          }
    
        });

    点击事件:

    <zan-button type="primary" bindtap="submit">确定</zan-button>

    当前选中处理:

    selectList(e) {
        const index = e.currentTarget.dataset.index;
    }

    深层数据修改:

     addCount(e) {
        const index1 = e.currentTarget.dataset.one;
        const index2 = e.currentTarget.dataset.two;
        var modifyKey = 'sortBysListArr[' + index1 + '][' + index2 + '].productNum'
        var newNum = this.data.sortBysListArr[index1][index2].productNum+1;
        this.setData({
          [modifyKey]: newNum
        })
        this.getAccountAll()
      },

    写入缓存:

    wx.setStorage({
            key: 'address',
            data: address,
            success() {
              wx.navigateBack();
              wx.showModal({
                  title: '提示',
                  content: '收货信息提交成功',
                  showCancel: false
           })
    }

    获取缓存:

      wx.getStorage({
          key: 'address',
          success: function(res){
            self.setData({
              address : res.data
            })
          }
        })
    或者:
        wx.getStorageSync('userId')
    
    

    受控组件:

    handleFieldChange(e) {
        var name = e.currentTarget.dataset.name;
        var key = 'address.' + name
        this.setData({
          [key]: e.detail.detail.value
        })
    },

    js页面跳转:

    
    
      <view class="cateItem" bindtap='turnToProlist' data-item="{{item}}" wx:for="{{cateGoryList}}" wx:key="{{index}}" wx:for-item="item">...</view>
    turnToProlist(e){
          let itemData=e.currentTarget.dataset.item;
          let data=JSON.stringify(itemData)
          wx.navigateTo({
            url: "/page/component/prolist/prolist?data=" + data,
          })
    }
    //to页面获取参数
    onLoad: function (options) {
          var proId = options.productId;
      }
     

    双层循环渲染:

     <view class="" wx:for="{{CheckedProArr}}" wx:key="{{index}}" wx:for-index="index1" wx:for-item="shopItem">
           <view class="box-header">店铺:{{shopItem[0].shopName}}</view>
              <view class="orders-box">
                 <view wx:for="{{shopItem}}" wx:key="index" class="orders-list" wx:key="{{index}}" wx:for-index="index2" wx:for-item="cartitem">
    .........................................................

    if判断:

    <view wx:if="{{ArticleItem.type=='title'}}">
         ........
    </view>
    <view wx:elif="{{ArticleItem.type=='text'}}">
    ........
    </view>
    <view wx:else>
    .........
    </view>
  • 相关阅读:
    P1135 奇怪的电梯题解
    P1443 马的遍历题解
    P2392 kkksc03考前临时抱佛脚题解
    P1219 八皇后问题题解
    IDEA导入/导出live templates或者其他设置
    P3743 kotori的设备题解
    带你看论文丨全局信息对于图网络文档解析的影响
    【“互联网+”大赛华为云赛道】EI命题攻略:华为云EI的能力超丰富,助你实现AI梦想
    【“互联网+”大赛华为云赛道】IoT命题攻略:仅需四步,轻松实现场景智能化设计
    只需6步,教你从零开发一个签到小程序
  • 原文地址:https://www.cnblogs.com/thing/p/9371349.html
Copyright © 2020-2023  润新知