微信小程序购物车选择规格颜色

软件发布|下载排行|最新软件

当前位置:首页IT学院IT技术

微信小程序购物车选择规格颜色

小丫么小菜菜   2022-05-23 我要评论

wxml:

<view>
  <view>规格:</view>
  <view class='dis'>
    <block wx:for="{{guige}}">
      <view class="{{gindex==index?'color':''}}" bindtap='guige' data-index='{{item.id}}' data-current='{{index}}'>{{item.name}}</view>
    </block>
  </view>
  <view>颜色:</view>
  <view class='dis'>
    <block wx:for="{{color}}">
      <view class="{{cindex==index?'color':''}}" bindtap='color' data-index='{{item.id}}' data-current='{{index}}'>{{item.name}}</view>
    </block>
  </view>
</view>
<view>{{guige[gindex].name}}:{{color[cindex].name}}</view>

js:

// pages/guige/guige.js
Page({
 
  /**
   * 页面的初始数据
   */
  data: {
    guige:[
      {id:1,name:'M'},
      {id:2,name:'L'},
      {id:3,name:'X'},
      {id:4,name:'S'}
    ],
    color:[
      {id:5,name:'红'},
      { id: 6, name: '橙'},
      { id: 7, name: '黄'},
      { id: 8, name: '绿'}
    ]
  },
  guige:function(e){
    this.setData({
      gid: e.currentTarget.dataset.index,
      gindex: e.currentTarget.dataset.current,
    })
  },
  color:function(e){
    this.setData({
      cid: e.currentTarget.dataset.index,
      cindex: e.currentTarget.dataset.current,
    })
  },
  /**
   * 生命周期函数--监听页面加载
   */
  onLoad: function (options) {
  
  },
 
  /**
   * 生命周期函数--监听页面初次渲染完成
   */
  onReady: function () {
  
  },
 
  /**
   * 生命周期函数--监听页面显示
   */
  onShow: function () {
  
  },
 
  /**
   * 生命周期函数--监听页面隐藏
   */
  onHide: function () {
  
  },
 
  /**
   * 生命周期函数--监听页面卸载
   */
  onUnload: function () {
  
  },
 
  /**
   * 页面相关事件处理函数--监听用户下拉动作
   */
  onPullDownRefresh: function () {
  
  },
 
  /**
   * 页面上拉触底事件的处理函数
   */
  onReachBottom: function () {
  
  },
 
  /**
   * 用户点击右上角分享
   */
  onShareAppMessage: function () {
  
  }
})

css:

.color{
  color: red
}
.dis{display: flex;justify-content: space-around}

Copyright 2022 版权所有 软件发布 访问手机版

声明:所有软件和文章来自软件开发商或者作者 如有异议 请与本站联系 联系我们