ios发送请求无法触发input的click事件

1,194 阅读1分钟

先说下在ios端触发input点击事件的两种方法:

方法一:
  <label class="upload">
      上传照片
      <input type="file" class="sr-only" id="inputImage" name="file" accept="image/*">
  </label>	
方法二:
  <div @click="startRecord()" class="face-link-btn">开始录制</div>
  <label class="upload" ref="starttest">
      <input
          v-show="false"
          id="imgFile"
          ref="startReal"
          accept="video/*"
          type="file"
          capture="user"
          @change="uploadVideo()"
      />
  </label>

然后我是用的第二种方法,然后遇到第二个问题在发送请求后没法触发,所以记录一下。

1.这种不能触发

    startRecord () {
        $.ajax({
            url: 'www.baidu.com',
            dataType: 'json',
            data: params,
            timeout: 10000,
            headers: {
                "Content-Type": 'application/x-www-form-urlencoded'
            },
            success: (res) => {
                if (res && res.code === 'SUC00000') {
                    this.$refs.starttest.click();  //不生效
                } else {}
            },
            error: function (err) {
                console.log(err);
            }
        });
    }

2.可以触发的(主要是加了同步处理和在外边调用(在请求内调用不生效))

    startRecord () {
    	let uploadflag = false
        $.ajax({
            url: 'www.baidu.com',
            dataType: 'json',
            data: params,
            async: false,(必须)
            timeout: 10000,
            headers: {
                "Content-Type": 'application/x-www-form-urlencoded'
            },
            success: (res) => {
                if (res && res.code === 'SUC00000') {
                    uploadflag = true;
                } else {}
            },
            error: function (err) {
                console.log(err);
            }
        });
        if (uploadflag) {
            this.$refs.starttest.click();
        }
    }

以上就是记录本次问题的全部了。也是第一次发文章。没什么经验多多关照。