zoukankan      html  css  js  c++  java
  • 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>
  • 相关阅读:
    java框架---->mybatis的使用(一)
    java基础---->数组的基础使用(二)
    python爬虫---->github上python的项目
    java基础---->git的使用(一)
    spring基础---->请求与响应的参数(一)
    织梦DEDECMS网站后台安全检测提示 加一个开关
    MySql的join(连接)查询 (三表 left join 写法)
    html只允许输入的数据校验,只允许输入字母汉字数字等
    js控制只允许输入数字
    DEDECMS里面DEDE函数解析
  • 原文地址:https://www.cnblogs.com/lhl66/p/14021709.html
Copyright © 2011-2022 走看看