• vant移动端popup + picker简易封装


    为了方便使用;

    <!--
     * @Description: vant测试
     * @Version: 2.0
     * @Autor: lhl
     * @Date: 2020-11-21 10:16:50
     * @LastEditors: lhl
     * @LastEditTime: 2020-11-22 21:47:10
    -->
    <template>
      <div>
        <div class="title" @click="showUp">你好</div>
        <van-button type="default">默认按钮</van-button>
        <van-button type="primary">主要按钮</van-button>
        <popUpPicker :columns="['java','js','vue']"  @changeValue="handelChange" ref="popup" :showPicker="showPicker" @close="handelChange"/>
      </div>
    </template>
    
    <script>
    import popUpPicker from '@/components/popUpPicker'
    
    export default {
        components:{
            popUpPicker
        },
        data(){
            return {
                showPicker: false
            }
        },
        methods:{
           showUp(){
               this.showPicker = true;
               console.log(this.$refs.popup)
           },
           handelChange(val){
               this.showPicker = false;
               console.log(val,'val')
           }
        }
    }
    </script>
    
    <style lang="scss" scoped>
    .title{
        font-size: 38px;
        width: 400px;
    }
    
    </style>
    <!--
     * @Description: 封装组件
     * @Version: 2.0
     * @Autor: lhl
     * @Date: 2020-11-22 17:19:30
     * @LastEditors: lhl
     * @LastEditTime: 2020-11-22 21:46:06
    -->
    <template>
      <div class="popup-pciker-wrap">
        <van-popup
          v-model="isPicker"
          round
          position="bottom"
          closeable
          close-icon="close"
          close-icon-position="top-left"
          @close="close"
        >
          <van-picker
            show-toolbar
            :columns="columns"
            @cancel="cancel"
            @confirm="onConfirm"
          />
        </van-popup>
      </div>
    </template>
    
    <script>
    export default {
      props: {
        showPicker: {
          type: Boolean,
          default: false,
        },
        columns: {
          type: Array,
          default: () => {
            return [];
          },
        },
      },
      watch: {
        isPicker (val) {
          !val && this.$emit('changeValue')
        },
        showPicker (val) {
          this.isPicker = val
        }
      },
      data () {
        return {
          isPicker: false
        }
      },
      methods: {
        onConfirm(value, index) {
          console.log(`当前值:${value}, 当前索引:${index}`);
          this.$emit('changeValue',value)
        },
        cancel() {
            this.$emit('changeValue')
        },
        close(){
            // this.$emit('close')
        }
      },
    }
    </script>
    
    <style>
    .van-picker__cancel{
        visibility: hidden;
    }
    
    </style>
  • 相关阅读:
    Android SQLite最简单demo实现(增删查改)
    最简单的自定义控件实现
    Android复杂自定义Listview实现
    Linux 下 实现 锐捷验证的方式
    Java EE学习路线
    ubuntu 12.04 配置-1
    Dream
    iOS UITextView设置富文本不能输入中文问题
    iOS UIScrollView滚动方法对比
    iOS 自定义View通知相关
  • 原文地址:https://www.cnblogs.com/lhl66/p/14021709.html
Copyright © 2020-2023  润新知