我的代码:
interface Item {
title: string;
type: string;
description: string;
}
data() {
return {
id: "",
item: {} as Item,
file: //Here
};
}
您好,我想为我的 vuejs 数据添加一个文件类型。
我看到了这个可行的解决方案:
interface Item {
title: string;
type: string;
description: string;
file: File;
}
data() {
return {
id: "",
item: {} as Item
};
}
但我不想将我的数据文件添加到我的 Item 界面或对象中。
最佳答案
您可以为数据本身编写一个接口(interface)
(或一个类型
),然后只向它添加文件
属性。
interface Item {
title: string;
type: string;
description: string;
}
interface State {
id: string;
item: Item;
file: null | File;
}
data(): State {
return {
id: '',
item: {
title: '',
type: '',
description: '',
},
file: null,
};
},
关于typescript - 如何使用 typescript 在 vuejs 中向我的数据添加 "File"类型?,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/61670153/