一、父组件通过ref调用子组件中的方法,子组件方法用public 定义函数报错
代码案例
报错信息
Declaration of public instance method not allowed after declaration of private instance method. Instead, this should come after private instance fields.
解决办法
将定义的public 方法放到最前面,(排在最前)
二、数组push 和对象映射
ps: 将对象映射变为数组模式
代码案例
报错信息
Conversion of type ‘string’ to type ‘1 | 2’ may be a mistake because neither type sufficiently overlaps with the other. If this was intentional, convert the expression to ‘unknown’ first.
报错翻译
解决办法
将数组中要push 的值和值 对应的类型一致就可以
拓展:
引用的 Option 类型为
引用的对象为(对象映射)
打印结果为
三、数组push
代码案例
报错信息
Argument of type ‘any’ is not assignable to parameter of type ‘never’.
解决办法
将数组定义好类型就可以
补充
// 问题写法
const wdData = [];
// 正确写法
connst wdData: any[] = [];
四、从地址栏里取参给表单赋值
代码案例
定义了this.addData.businessIncharge = ’ ’
报错信息
Type ‘string | (string | null)[]’ is not assignable to type ‘string’.
Type ‘(string | null)[]’ is not assignable to type ‘string’.
解决方法 [加上 as string 就可以]
this.addData.businessIncharge = (this.$route.query.misID as string) || ''