const formData:any = new FormData();
const data = {
name: 'admin',
age: 18
}
for (const [key, value] of Object.entries(data)) {
formData.append(key, value)
}
const fileList = this.fileList
if (fileList && fileList.length > 0) {
for (const item of this.fileList) {
formData.append('file', item.file)
}
}
报错了
Argument of type 'string | LocationQueryValue[] | null' is not assignable to parameter of type 'string | Blob'.
请问怎么声明这个formData的类型?用any倒是也可以,但是既然用了typescript 就想知道怎么写
###import { defineComponent } from 'vue'
import { LocationQueryValue } from 'vue-router' // 可以引入这个类型
interface Data {
types: string | LocationQueryValue[] | null;
}
export default defineComponent ({
data (): Data {
types: ''
},
...
})
###错误提示是说,你的value
的类型不对。value
的类型应当是string
或者Blob
类型,而你的value
可能是LocationQueryValue[]
类型