Vue hidden trigger input file method

1, a transparent cover using the input method

  The input of the z-index is set to 1 or more to cover digital content and the need to click the input style opacity is set to 0 (that is, transparency is 0), so by binding on the input of the change event triggers - --recommend

<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, using the ref parameter vue direct manipulation input click event triggers

<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, using HTML lable mechanism triggering input events

<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 () {},     // trigger event   
uploadPic: function () { 
  the console.log ( 'DSA' ); 
}

  change event for property on the lable binding input of id, to trigger input by clicking on the event trigger lable ---- recommendation

Guess you like

Origin www.cnblogs.com/wangjishu/p/11350999.html