我需要在我的jQueryUI项目中使用来自VueJS的可排序插件,但是我不知道如何在VueJS 2项目中包含库。
这就是我到目前为止所做的:
1)以这种方式安装jQuery和jQueryUI
npm install --save jquery-ui
npm install --save jquery2)我将这些行添加到main.js中:
window.$ = window.jQuery = require('jquery');
window.$ = $.extend(require('jquery-ui'));3)我在我的组件上这样使用:
<div class="height">
<app-component-component></app-component-component>
</div>
....
export default {
components: {
appComponentComponent: ComponentComponent
},
...
mounted() {
$('.height').sortable();
}
}但我知道这个错误:
[Vue warn]: Error in mounted hook: "TypeError: $(...).sortable is not a function"你能告诉我我做错了什么才能导入和使用这个库吗?
提前感谢
发布于 2017-10-30 23:07:01
您可以将可排序的插件代码放在vue生命周期的更新()方法中。
updated()
{
this.$nextTick(function () {
jQuery('.height').sortable();
})
}发布于 2020-10-15 19:02:16
您必须将其添加到main.js中。
global.jQuery = require('jquery');
var $ = global.jQuery;
window.$ = $;
require('jquery-ui');
require('jquery-ui/ui/widgets/sortable');你可以用它装在里面,就像你一样。
https://stackoverflow.com/questions/47025351
复制相似问题