vue.js - Hur lägger jag till en "Fil"-typ till mina data i vuejs med typescript?
Min kod:
interface Item {
title: string;
type: string;
description: string;
}
data() {
return {
id: "",
item: {} as Item,
file: //Here
};
}
Hej, jag letar efter att lägga till en filtyp till mina Vue.js-data.
Jag såg den här lösningen som skulle kunna fungera:
interface Item {
title: string;
type: string;
description: string;
file: File;
}
data() {
return {
id: "",
item: {} as Item
};
}
men jag vill inte lägga till min datafil i mitt Item-gränssnitt eller i ett objekt.
Svar #1
Du kan skriva ett interface (eller en type) till själva datan och bara lägga till file-egenskapen till det.
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,
};
},
