我们在SPA应用程序上使用了Dragula(拖放式)JS Lib。 在更改页面时,我需要删除JS库的帮助。当我返回时,收到以下错误消息:“ Dragula不是函数”。
正如文档在Github页面底部所建议的那样,我试图用drake.destroy删除Dragula。但是还没有解决。我考虑将this.dragula作为eventListener移除,即removeEventListener。但是我不确定该想法如何成功。
错误消息是:
Uncaught TypeError: Dragula is not a function
at startDragula (sitebrowse.js:361)
at showBrowseView (sitebrowse.js:12)
at doEvent (router.js:51)
at router.js:4
它指向sitebrowse.js第361行。
function startDragula() {
if (shoppingCart === 0) {
$('#dragula_right').addClass("empty-shopping-cart");
/*Line 361 */ this.dragula =
dragula([document.querySelector('#dragula_left'), document.querySelector('#dragula_right')], {
copy: function (el, source) {
/* console.log("copied: " + el + " to source " + source); */
return source === document.getElementById('dragula_left');
},
moves: function (el, source, handle, sibling) {
return source === document.getElementById('dragula_left'); // elements are always draggable by default
},
accepts: function (el, target) {
return target !== document.getElementById('dragula_left');
},
copySortSource: false
});