我在vue中使用打字稿 并使用document.fonts api 但请管理该日志
Property 'fonts' does not exist on type 'Document'
答案 0 :(得分:1)
将其添加到环境声明文件中,例如src/index.d.ts
type CSSOMString = string;
type FontFaceLoadStatus = 'unloaded'|'loading'|'loaded'|'error';
type FontFaceSetStatus = 'loading'|'loaded';
interface FontFace {
family: CSSOMString;
style: CSSOMString;
weight: CSSOMString;
stretch: CSSOMString;
unicodeRange: CSSOMString;
variant: CSSOMString;
featureSettings: CSSOMString;
variationSettings: CSSOMString;
display: CSSOMString;
readonly status: FontFaceLoadStatus;
readonly loaded: Promise<FontFace>;
load(): Promise<FontFace>;
}
interface FontFaceSet {
readonly status: FontFaceSetStatus;
readonly ready: Promise<FontFaceSet>;
check(font: string, text?: string): Boolean;
load(font: string, text?: string): Promise<FontFace[]>
}
declare global {
interface Document {
fonts: FontFaceSet
}
}
答案 1 :(得分:0)
实验性API不在lib文件中。
您可以使用以下方法进行修复:(document as any).fonts