Browse Source

fix(shortpassword): 修复value不能清空,渲染报错问题

Drjingfubo 4 years ago
parent
commit
b1275ba74b

+ 17 - 5
src/packages/__VUE/shortpassword/index.taro.vue

@@ -120,18 +120,24 @@ export default create({
     const comLen = computed(() => range(Number(props.length)));
     const show = ref(props.visible);
     const isWx = ref(false); // 判断是否为微信端
+    const dom = ref();
     // 方法
     function sureClick() {
       emit('ok', realInput.value);
     }
     function focus() {
-      let a: any = '';
+      let dom: any = '';
       if (isWx.value) {
-        a = document.getElementsByClassName('nut-input-real-taro')[0] as any;
-        a.focus();
+        setTimeout(() => {
+          dom = document.getElementsByClassName(
+            'nut-input-real-taro'
+          )[0] as any;
+          if (!dom) return;
+          dom.focus();
+        }, 100);
       } else {
-        a = document.getElementsByClassName('nut-input-real')[0] as any;
-        let h = a.children[0];
+        dom = document.getElementsByClassName('nut-input-real')[0] as any;
+        let h = dom.children[0];
         h.focus();
       }
     }
@@ -141,6 +147,12 @@ export default create({
         show.value = value;
       }
     );
+    watch(
+      () => props.modelValue,
+      (value) => {
+        realInput.value = value;
+      }
+    );
     function changeValue(e: Event) {
       const input = e.target as HTMLInputElement;
       let val = input.value;

+ 7 - 0
src/packages/__VUE/shortpassword/index.vue

@@ -123,6 +123,13 @@ export default create({
         show.value = value;
       }
     );
+    watch(
+      () => props.modelValue,
+      (value) => {
+        realInput.value = value;
+        console.log('watch', value);
+      }
+    );
     function changeValue(e: Event) {
       const input = e.target as HTMLInputElement;
       let val = input.value;