2016-07-22 82 views
0

我创建简单的测试程序来证明我的问题browserify的jQuery + jQuery的用户界面并不适用于我

https://github.com/alexey2baranov/jquery-ui-broken-demo

在这个演示中,我首先是龙头安装的jQuery和jQuery UI的

npm install --save jquery jquery-ui 

然后创建简单的测试脚本

window.$ = window.jQuery = require("jquery"); 
require('jquery-ui'); 


$(function(){ 
    $('#qwerty').draggable(); 
}); 

,并与BR将它们编owserify

browserify --debug index.js -o dist/index.js 

在最终的步骤我装browserify结果到测试HTML页面

<head> 
    <script src="dist/index.js"></script> 
</head> 
<body> 

<div id="qwerty" style="position: absolute; width: 100px; height: 100px; background-color: #0b3e6f">123</div> 
</body> 

,并获得在Chrome控制台此错误

jQuery.Deferred exception: $(...).draggable is not a function TypeError: $(...).draggable is not a function at HTMLDocument. undefined index.js [sm]:10Uncaught TypeError: $(...).draggable is not a function

这有什么错我的代码?

+0

鉴于此错误消息,出于某种原因,您包含的jQueryUI库无法正常工作。 –

+0

Yap!希望sombody得到相同的错误,并可以修复它 – alexey2baranov

回答

0
import $ from 'jquery' 
import 'jquery-ui/ui/widgets/draggable' 

$("#draggable").draggable(); 
+0

虽然这段代码可以解决这个问题,[包括解释](// meta.stackexchange.com/questions/114762/explaining-entirely-code-based-answers)真的有帮助以提高您的帖子的质量。请记住,您将来会为读者回答问题,而这些人可能不知道您的代码建议的原因。也请尽量不要使用解释性注释来挤占代码,因为这会降低代码和解释的可读性! – FrankerZ

+0

同意在这里需要更多解释。 加上这段代码可能不起作用,因为导入的文件会调用未定义的'$ .ui.mouse'。 – micky2be