svg.js不使用Typescript和Stencil.js
我有一个用Typescript构建的基本模具应用程序。 我没有使用角度。 我无法使用svg.js 以下是我的全部内容:svg.js不使用Typescript和Stencil.js,typescript,svg.js,stenciljs,Typescript,Svg.js,Stenciljs,我有一个用Typescript构建的基本模具应用程序。 我没有使用角度。 我无法使用svg.js 以下是我的全部内容: import { Component, State } from '@stencil/core'; import * as moment from 'moment'; import * as SVG from 'svg.js'; @Component({ tag: 'astro-sandbox', styleUrl: 'sandbox.css' }) export c
import { Component, State } from '@stencil/core';
import * as moment from 'moment';
import * as SVG from 'svg.js';
@Component({
tag: 'astro-sandbox',
styleUrl: 'sandbox.css'
})
export class AstroSandbox {
componentDidLoad() {
// console.info(SVG)
let drawing = SVG('drawing');
}
render() {
return (
<div>
<div id="drawing">
</div>
</div>
);
}
}
从'@stencil/core'导入{Component,State};
从“时刻”导入*作为时刻;
从“SVG.js”导入*作为SVG;
@组成部分({
标签:“astro沙盒”,
styleUrl:'sandbox.css'
})
导出类沙箱{
componentDidLoad(){
//console.info(SVG)
让绘图=SVG(“绘图”);
}
render(){
返回(
);
}
}
此操作失败,{错误:无法调用命名空间('SVG')…
我试着用console.info('SVG')查看SVG,它可以编译,但是浏览器给了我错误
TypeError:无法设置未定义的属性“SVG”
我知道我的应用程序可以正常工作,我让moment.js正常工作,所以没有TS配置问题。VS代码中svg.js的Intellisense也可以正常工作。这是svg.js中的一个已知错误。你可以看到相应的问题。问题是,svg.js将自身添加到
中。在ECMAscript 262中此在c中未定义防止在窗口对象中乱丢东西。同时,您可以使用此PR的代码:,因为导入无法正常工作。请尝试从SVG.js导入SVG或使用require。