NHZEX / nxAdmin-soybean-admin

Soybean Admin Fork
https://soybeanjs.cn
MIT License
0 stars 0 forks source link

[Vue] 备忘录 #4

Open NHZEX opened 3 months ago

NHZEX commented 3 months ago

状况

错误1

定义const a = ref<T[]>([]),使用a.value.find(...)取出的值传递到函数function x(val: T)时会报告类似下方的错误内容:

 Two different types with this name exist, but they are unrelated.
        Types of property '...' are incompatible.
          Type '...' is not assignable to type 'Readonly<Ref<...>>'.

尝试可用的方法:

  1. const a = ref<T[]>([]) as Ref<T[]>,这样定义不需要修改接受传入值的地方。
  2. function x(val: UnwrapRef<T>),这样定义传入值时不在报错。

错误2

定义

const model = ref<T>(...)
const v1= computed<T>({
  get: () => model.value.xxx,
  set: value => {
    model.value.xxx= value;
  }
});

报告类似下方的错误内容:

# ERR-1
Vue: No overload matches this call.
Overload 1 of 2,
(getter: ComputedGetter<T>, debugOptions?: DebuggerOptions | undefined): ComputedRef<T>
, gave the following error.
Overload 2 of 2,
(options: WritableComputedOptions<T>, debugOptions?: DebuggerOptions | undefined): WritableComputedRef<...>
, gave the following error.

# ERR-1
Vue: Parameter value implicitly has an any type.

尝试可用的方法:

const v1= computed<T>({
  get: () => model.value.xxx as T,
  set: value => {
    model.value.xxx = value as UnwrapRef<T>;
  }
});

可能相关资料

遇到类似问题