Przeglądaj źródła

fix type warning

Michael Wang 3 lat temu
rodzic
commit
5447224d74
1 zmienionych plików z 33 dodań i 33 usunięć
  1. 33 33
      src/components/QmButton.vue

+ 33 - 33
src/components/QmButton.vue

@@ -9,42 +9,42 @@
 </template>
 
 <script lang="ts">
-import { reactive } from "vue";
-
-// 默认loading一秒,以免重复点击
 export default {
-  name: "QmButton",
   inheritAttrs: false,
-  props: {
-    clickTimeout: { type: Number, required: false, default: 1000 },
-  },
-  // @ts-ignore
-  setup(props, { attrs }) {
-    let newAttrs = reactive({});
-    Object.assign(newAttrs, attrs);
-    let parentOnClick = attrs.onClick;
-    // @ts-ignore
-    delete newAttrs["onClick"];
+};
+</script>
 
-    let inInterval = $ref(false);
-    const insideClick = (e: MouseEvent) => {
-      inInterval = true;
-      // false warning
-      // eslint-disable-next-line @typescript-eslint/no-unsafe-argument
-      setTimeout(() => (inInterval = false), props.clickTimeout);
-      // eslint-disable-next-line @typescript-eslint/no-unsafe-call
-      parentOnClick(e);
-      // 确保焦点不停留在此处,以免Enter键触发
-      // @ts-ignore
-      // eslint-disable-next-line @typescript-eslint/no-unsafe-call
-      e.target?.blur();
-    };
-    // newAttrs.onClick = insideClick;
+<script setup lang="ts">
+import { reactive, useAttrs } from "vue";
 
-    function asAny(input: any): any {
-      return input;
-    }
-    return { newAttrs, inInterval, insideClick, asAny };
-  },
+// 默认loading一秒,以免重复点击
+// TODO: https://github.com/vuejs/rfcs/discussions/369  defineProps deconstructure retain reactivity
+// eslint-disable-next-line vue/no-setup-props-destructure
+const { clickTimeout = 1000 } = defineProps<{ clickTimeout?: number }>();
+
+const attrs = useAttrs();
+let newAttrs = reactive({});
+Object.assign(newAttrs, attrs);
+let parentOnClick = attrs.onClick;
+// @ts-ignore
+delete newAttrs["onClick"];
+
+let inInterval = $ref(false);
+const insideClick = (e: MouseEvent) => {
+  inInterval = true;
+  // false warning
+  // eslint-disable-next-line @typescript-eslint/no-unsafe-argument
+  setTimeout(() => (inInterval = false), clickTimeout);
+  // eslint-disable-next-line @typescript-eslint/no-unsafe-call
+  // @ts-ignore
+  parentOnClick(e);
+  // 确保焦点不停留在此处,以免Enter键触发
+  // @ts-ignore
+  // eslint-disable-next-line @typescript-eslint/no-unsafe-call
+  e.target?.blur();
 };
+
+function asAny(input: any): any {
+  return input;
+}
 </script>