1,定义对象后扩展对象属性报错
报错详情:Property ‘id’ does not exist on type ‘query’.Vetur(2339)
例如:
let query = {name: 'aa'}
if (id) {
query.id = id // Property 'id' does not exist on type 'query'.Vetur(2339)
}
解决方法,添加代码:
interface queryObject {
name: String
[prop: string]: any
}
let query: queryObject = {name: 'aa'}
if (id) {
query.id = id
}