[英]Import and use external Typescript module in Vue component
I'm pretty new to Vue and am trying to use an external Typescript module in my Vue Component to render a guitar fretboard ( https://github.com/omnibrain/svguitar ).我对 Vue 很陌生,我正在尝试在我的 Vue 组件中使用外部 Typescript 模块来渲染吉他指板( https://github.com/omnibrain/svguitar )。 Ideally I would like to be able to render these in different locations of my application.
理想情况下,我希望能够在我的应用程序的不同位置呈现这些。 I've followed the steps in the
ReadMe.md
but can't get it to work.我已按照
ReadMe.md
的步骤操作,但无法使其正常工作。 This is what my component looks like:这是我的组件的样子:
<template>
<div class="home">
<div class="chart" />
</div>
</template>
<script lang="ts">
import Vue from "vue";
import { SVGuitarChord } from "svguitar";
const chart = new SVGuitarChord("#chart");
export default Vue.extend({
mounted() {
console.log("I'm mounted");
chart
.configure({
strings: 6,
frets: 5
})
.chord({
fingers: [],
barres: []
})
.draw();
}
});
</script>
Doing this, I receive the following error in my console:这样做后,我在控制台中收到以下错误:
TypeError: Cannot read property 'put' of null
at Svg.addTo (svguitar.es5.js?98dc:2746)
at new SvgJsRenderer (svguitar.es5.js?98dc:7478)
at SVGuitarChord.get (svguitar.es5.js?98dc:7654)
at SVGuitarChord.clear (svguitar.es5.js?98dc:8021)
at SVGuitarChord.draw (svguitar.es5.js?98dc:7685)
at VueComponent.mounted (Home.vue?42b8:20)
at invokeWithErrorHandling (vue.runtime.esm.js?2b0e:1854)
at callHook (vue.runtime.esm.js?2b0e:4219)
at Object.insert (vue.runtime.esm.js?2b0e:3139)
at invokeInsertHook (vue.runtime.esm.js?2b0e:6346)
Would be great if somebody could heb me out to get this to work!如果有人能帮我解决这个问题,那就太好了! If any additional information is needed, please let me know.
如果需要任何其他信息,请告诉我。
This happen because you specify #chart
as container to SVGuitarChord
but you write <div class="chart" />
.这发生,因为你指定
#chart
作为容器SVGuitarChord
但你写<div class="chart" />
It should be <div id="chart" />
它应该是
<div id="chart" />
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.