zoukankan      html  css  js  c++  java
  • Vue触发隐藏input file的方法

    1、使用input透明覆盖法

      将input的z-index设置为1以上的数字并覆盖到需点击的内容上,将input的样式opacity设置为0(即为透明度为0),这样通过绑定在input上的change事件触发     ----推荐

    <p class="uploadImg">
        <input type="file" @change="picUpload($event)" accept="image/*" />
    </p>
    .uploadImg {
        width: 100%;
        height: 1.46rem;
        position: relative;
        input {
          width: 1.46rem;
          height: 100%;
          z-index: 1;
          opacity: 0;
          position: absolute;
          cursor: pointer;
        }
    }

    2、使用vue的ref参数直接操作input的点击事件触发

    <div class="upload-btn-box">
      <Button @click="choiceImg" icon="ios-cloud-upload-outline" type="primary">点击上传</Button>
       <input ref="filElem" type="file" class="upload-file" @change="getFile">
    </div>
    choiceImg(){
        this.$refs.filElem.dispatchEvent(new MouseEvent('click')) 
    },
    getFile(){
        console.log("成功");
    }

    3、使用HTML的lable机制触发input事件

    <label for="upfile" class="pTitleRight" @click="IDRecognition">
    <span>身份证识别</span>
        <i class="iconfont">&#xe612;</i>
        <input ref="filElem" type="file" accept="image/*" id="upfile" name="upfile" style="display: none;" @change="uploadPic">
    </label>
    IDRecognition: function() {},    //触发事件  
    uploadPic: function() {
      console.log('dsa');
    }

      lable上的for属性绑定input的id,即可通过触发lable上的点击事件触发input的change事件    ----推荐

  • 相关阅读:
    Codeforces 1009F Dominant Indices
    UOJ #35 后缀排序 哈希做法
    bzoj 3670 [Noi2014]动物园
    动态规划 笔记

    常用模块和面向对象 类
    常用模块
    包的使用和常用模块
    日志
    复习列表,模块
  • 原文地址:https://www.cnblogs.com/wangjishu/p/11350999.html
Copyright © 2011-2022 走看看