使用 TS 类组件
导入 sortableJs/vuedraggable 时出现错误。
将 vuedraggable
与标准 JS 标准组件
一起使用时,它工作正常。
这是我的带有标准 JS 组件的 vuedraggable:
<script>
import draggable from "vuedraggable";
export default {
components: {
draggable
},
...
一切正常,没有错误。
这是我的带有 TS 类组件 的 vuedraggable:
<script lang="ts">
import { Component, Vue } from "vue-property-decorator";
import draggable from "vuedraggable";
@Component({
components: {
draggable
}
})
export default class Board extends Vue {
...
此处发生错误
Could not find a declaration file for module 'vuedraggable'.
implicitly has an 'any' type. Try
npm install @types/vuedraggable
if it exists or add a new declaration (.d.ts) file containing `declare module 'vuedraggable
所以我做到了:
npm install @types/vuedraggable
npm ERR! 404 '@types/vuedraggable@latest' is not in the npm registry.
如何在 Typescript 类组件中使用 vuedraggable?
最佳答案
您可以创建一个本地类型文件并添加 vuedraggable
的声明,如 github issue 中所述作为解决方法,直到 PR which adds the typings to the library被合并。
关于javascript - 具有 vuedraggable 的 Vue typescript 类组件,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/60212234/