在Aurelia中使用jQuery [英] Using jQuery with Aurelia
问题描述
我有一个Aurelia应用,在app.js中我想使用jQuery.
I have an Aurelia app and in app.js I want to use jQuery.
所以我的config.js看起来像:
So my config.js looks like:
System.config({
...
map: {
...
"jquery": "npm:jquery@2.2.0",
...
}
}
在app.js中,我像这样导入jQuery:
And in app.js I import the jQuery like this:
var $ = require('jquery');
但是当我需要它时,我得到了一个空白站点.与导入相同:
But when I require it, I get the blank site. Same it was with import:
import $ from 'jquery';
怎么了?
谢谢
好,解决了.问题是,必须在Attached()方法内部调用jQuery代码.像这样:
ok, solved. The problem is, the jQuery code must be called inside the attached() mehtod. So like this:
export class Class1 {
attached() {
//jQuery code here
}
}
推荐答案
您需要从 https://github.com/components安装jquery/jquery
但是,如果您使用aurelia-skeleton,则可以从bootstrap
But if you use aurelia-skeleton, you can import it from bootstrap
import 'bootstrap';
,然后在应用程序中的任何地方使用$
,或者
and then use $
everywhere in app, or
import $ from 'bootstrap'
与jqueryui相同.如果需要,请从 https://github.com/components/jqueryui
Same is for jqueryui. If needed get it from https://github.com/components/jqueryui
这篇关于在Aurelia中使用jQuery的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!