【发布时间】:2021-01-25 00:00:20
【问题描述】:
我的目标是在 Vuejs2 和 Typescript 中使用 sortablejs 的 MultiDrag 功能。
docs 说:
MultiDrag 是一个用于 SortableJS 的插件,并不包含在所有 Sortable 的构建。它在主程序中开箱即用 Sortable.js 文件,但在模块化构建中默认不挂载 (除了在 sortable.complete.esm.js 中)。从模块化安装它 构建,只需按照以下代码:
import { Sortable, MultiDrag } from 'sortablejs';
Sortable.mount(new MultiDrag());
我在 repo 中找到了sortable.complete.esm.js,但我不知道将它放在我的项目目录结构中的哪个位置,以便上面的 import 语句起作用。
我试过了
% npm install ~/gitrepos/sortablejs/modular/sortable.complete.esm.js
npm ERR! code ENOLOCAL
npm ERR! Could not install "../../../../sortablejs/modular/sortable.complete.esm.js" as it is not a directory and is not a file with a name ending in .tgz, .tar.gz or .tar
我尝试将文件复制到我的/node_modules 目录中,然后:
import { Sortable, MultiDrag } from "sortablejs";
失败:
未找到此依赖项:
* sortablejs in ./node_modules/cache-loader/dist/cjs.js??ref--14-0!./node_modules/babel-loader/lib!./node_modules/ts-loader??ref--14-2!./node_modules/cache-loader/dist/cjs.js??ref--0-0!./node_modules/vue-loader/lib??vue-loader-options!./src/components/Pages.vue?vue&type=script&lang=ts&
如何挂载这个文件?
========================更新======================= =====
我遵循了以下 dwosk 的建议,这是我看到的错误:
warning in ./src/main2.ts
"export 'MultiDrag' was not found in 'sortablejs'
ERROR in /Users/jeff/gitrepos/code/code/paidmerge/from-vue/src/main2.ts(11,10):
11:10 'Sortable' can only be imported by using a default import.
9 | import 'bootstrap-vue/dist/bootstrap-vue.css'
10 |
> 11 | import { Sortable, MultiDrag } from 'sortablejs';
| ^
12 |
13 | Sortable.mount(new MultiDrag());
14 |
【问题讨论】:
标签: typescript npm vuejs2 sortablejs