Browse Source

fix(uploader): taro env 多组件多accept限制bug #1448

richard1015 3 years ago
parent
commit
e2867b0d24
1 changed files with 15 additions and 11 deletions
  1. 15 11
      src/packages/__VUE/uploader/index.taro.vue

+ 15 - 11
src/packages/__VUE/uploader/index.taro.vue

@@ -144,6 +144,21 @@ export default create({
       if (props.disabled) {
       if (props.disabled) {
         return;
         return;
       }
       }
+
+      if (Taro.getEnv() == 'WEB') {
+        let el = document.getElementById('taroChooseImage');
+        if (el) {
+          el?.setAttribute('accept', props.accept);
+        } else {
+          const obj = document.createElement('input');
+          obj.setAttribute('type', 'file');
+          obj.setAttribute('id', 'taroChooseImage');
+          obj.setAttribute('accept', props.accept);
+          obj.setAttribute('style', 'position: fixed; top: -4000px; left: -3000px; z-index: -300;');
+          document.body.appendChild(obj);
+        }
+      }
+
       Taro.chooseImage({
       Taro.chooseImage({
         // 选择数量
         // 选择数量
         count: props.multiple ? (props.maximum as number) * 1 - props.fileList.length : 1,
         count: props.multiple ? (props.maximum as number) * 1 - props.fileList.length : 1,
@@ -332,17 +347,6 @@ export default create({
       });
       });
     };
     };
 
 
-    onMounted(() => {
-      if (Taro.getEnv() == 'WEB') {
-        const obj = document.createElement('input');
-        obj.setAttribute('type', 'file');
-        obj.setAttribute('id', 'taroChooseImage');
-        obj.setAttribute('accept', props.accept);
-        obj.setAttribute('style', 'position: fixed; top: -4000px; left: -3000px; z-index: -300;');
-        document.body.appendChild(obj);
-      }
-    });
-
     return {
     return {
       onDelete,
       onDelete,
       fileList,
       fileList,