xiao

.............

小程序常用片段

生命周期:

 

 

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>

 

posted @ 2018-07-26 13:49  蓝色风暴003  阅读(397)  评论(0编辑  收藏  举报