• 基于 mpvue 框架的小程序选择控件,支持单列,多列,联动


    最近在学着写mpvue小程序,在做选择控件时候遇到了点问题,按照微信小程序方法picker,很不方便!

    在网上搜到一个很好用的组件下面给大家分享:

    组件说明文档链接:https://go.ctolib.com/article/wiki/84754

    我想说的是:按照说明文档并不能实现picker,后来幸运的是,作者有一个

    源码链接:https://github.com/MPComponent/mpvue-picker

    通过读源码,最后实现了picker

    我用的是二级联动:

    方法是:

    首先:

    安装 mpvue-picker

    npm install mpvue-picker --save

    然后页面代码为:

    <template>
          <div class="time-box male">
            <mpvue-picker class="time-box male" :mode="mode" :deepLength=deepLength ref="mpvuePicker" :pickerValueArray="pickerValueArray" :pickerValueDefault="pickerValueDefault" @onConfirm="onConfirm"></mpvue-picker>
            <div class="time-box" @click="showPicker">
              <image class="time-img" src='../../static/images/newest/time.png'/>
              <text class="time-text">按期查询</text>
            </div>
          </div>
    </template>
    
    <script>
    import mpvuePicker from "mpvue-picker"; export default { components: { mpvuePicker }, data() { return { allBulletin: [], mode: 'selector', deepLength: 0, // 几级联动 pickerValueDefault: [], // 初始化值 pickerValueArray: [], // picker 数组值 pickerText: '', mulLinkageTwoPicker: [ { label: '飞机', value: 0, children: [ { label: '经济舱', value: 1 }, { label: '商务舱', value: 2 } ] }, { label: '火车票', value: 1, children: [ { label: '卧铺', value: 1 }, { label: '坐票', value: 2 }, { label: '站票', value: 3 } ] }, { label: '汽车票', value: 3, children: [ { label: '快班', value: 1 }, { label: '普通', value: 2 } ] } ], pickerValueDefault: [0,0] }; }, onLoad() { var newest = String(this.$mp.query.type); this.$http .post( "https://tashimall.miniprogram.weixin-api-test.yokead.com/bulletin/getBulletin.json", "type=" + newest ) .then(res => { //输出请求数据 this.allBulletin = res.data.data; }) .catch(err => { console.log(err.status, err.message); }); }, methods: { showPicker() { this.pickerValueArray = this.mulLinkageTwoPicker; this.mode = 'multiLinkageSelector'; this.deepLength = 2; this.pickerValueDefault = [1, 0]; this.$refs.mpvuePicker.show(); console.log(this); }, onConfirm(e) { console.log(e); } } }; </script> <style> .time-box { display: flex; align-items: center; justify-content: center; float: left; width: 210rpx; height: 64rpx; background: #ff8308; border-radius: 15rpx; } .male { margin-left: 22rpx; } .time-img { width: 36rpx; height: 36rpx; } .time-text { font-size: 28rpx; color: #fff; margin-left: 10rpx; } </style>

    需要注意的是:如果你是其他(单列,多列,二级联动,三级联动)中的任意一种,务必看源码。

    地址是:

    https://github.com/MPComponent/mpvue-picker

  • 相关阅读:
    mybatis专题(一)-----入门、配置
    如何在抽象类中注入bean
    spring是如何解决循环依赖的?
    Java 程序员必须了解的计算机底层知识!
    数据库底层到底是怎么设计的?
    关于Rigidbody,Collider和CharacterController三者之间的关系和用法的总结
    泛型c#(深入理解c#)
    协程的NullReferenceException 错误
    进度条的制作unity
    Rigidbody.Is Kinematic和碰撞体
  • 原文地址:https://www.cnblogs.com/Webzhoushifa/p/9557045.html
Copyright © 2020-2023  润新知