微信小程序滑动选择器

  实现微信小程序滑动选择效果

  在wxml文件中,用一个picker标签代表选择器,bindchange是用户点击确定后触发的函数,index是picker自带的参数,用户点击确定后,bindchange绑定的函数用.detail.value就可以访问到。第一个选择的index值为0,依次递增。range要在page的data中先定义一个数组给它赋值,然后数组的值就会变为选择器中的选项

    <picker bindchange="bindPickerChange" value="{{index}}" range="{{array}}">
      <view  class='choseQuestion' >
        {{choseQuestionBank}}
      </view>
    </picker>

  js文件中对应的数据和函数如下

Page({
  data:{
    array:['全部','计算机网络','算法','数据结构','linux'],
    type:0,
    choseQuestionBank:"点击选择"
  },
  bindPickerChange: function (e) {
    var that=this
    console.log('picker发送选择改变,携带值为', e.detail.value)
    this.setData({
      type: e.detail.value,
      choseQuestionBank: that.data.array[e.detail.value]
    })
  },
})

  点击确认选择的时候,只要判断一下this.data.type的值就可以实现不同的选择了。

原文地址:https://www.cnblogs.com/luozx207/p/9453245.html