javascript - 具有 vuedraggable 的 Vue typescript 类组件

标签 javascript typescript vue.js vuejs2 vuedraggable

使用 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/

相关文章:

javascript - 查询连接两个表,但另一个表需要位于另一个内部数组中

javascript - Jquery.highlight <a> onclick

javascript - 使用 SASS 的 Angular 应用程序中的动态主题

javascript - 为什么使用 Return 函数调度 React Actions

asp.net - Typescript 2.7 中的严格类初始化

TypeScript 提示 'implicit any' 或 'possibly undefined',即使这是不可能的

vue.js - Amplify Vue amplify-authenticator 组件不显示

javascript - 尽管模仿了一个工作组件,VueJS 还是给我一个 "unknown custom element"错误

tsconfig.json 中的 typescript outDir 设置不起作用

javascript - 如何在 ES6 中的 Vue.js 中使用谷歌地图