Skip to content

Commit

Permalink
fix: 修复类型
Browse files Browse the repository at this point in the history
  • Loading branch information
Tyh2001 committed Apr 27, 2023
1 parent 77a7b1b commit a39c407
Show file tree
Hide file tree
Showing 2 changed files with 7 additions and 6 deletions.
11 changes: 6 additions & 5 deletions packages/fighting-design/_hooks/use-model/index.ts
Original file line number Diff line number Diff line change
@@ -1,7 +1,8 @@
import { computed } from 'vue'
import type { WritableComputedRef } from 'vue'

type Emit<T, K extends keyof T> = (key: string | number | symbol, value: T[K]) => void
/** emit 类型 */
type Emit = (event: 'update:modelValue', val: string | number) => void

export interface UseModelReturn<T, K extends keyof T> {
keyword: WritableComputedRef<T[K]>
Expand All @@ -17,11 +18,11 @@ export interface UseModelReturn<T, K extends keyof T> {
* @param { string } emitName emit 指定的返回键名
* @returns { Object } 自定义计算属性
*/
export const useModel = <T, K extends keyof T, E extends Emit<T, K>, N extends keyof E>(
export const useModel = <T, K extends keyof T>(
prop: T,
propName: K,
emit: E,
emitName: N
emit: Emit,
emitName: 'update:modelValue'
): UseModelReturn<T, K> => {

/**
Expand All @@ -34,7 +35,7 @@ export const useModel = <T, K extends keyof T, E extends Emit<T, K>, N extends k
return prop[propName]
},
set: (val: T[K]): void => {
emit(emitName, val)
emit(emitName, val as string | number)
}
})

Expand Down
2 changes: 1 addition & 1 deletion start/src/App.vue
Original file line number Diff line number Diff line change
Expand Up @@ -16,7 +16,7 @@
{{ ruleForm }}
<f-form label-width="90px" label-position="left" :on-submit="handelSubmit">
<f-form-item label="账号">
<f-input v-model="ruleForm.account" type="text" placeholder="请输入账号" />
<f-input v-model="ruleForm.account" :max-length="6" type="text" placeholder="请输入账号" />
</f-form-item>

<f-form-item label="密码">
Expand Down

0 comments on commit a39c407

Please sign in to comment.