我已经通过jspm install foundation安装了基础,然后导入了基础和jquery.
我遇到的问题是,如果我通过import $ as 'jquery'
我导入jquery 得到错误jquery_1.default不是一个函数.如果我通过import * as $ from jquery
它导入jquery 按预期工作
我打电话 $(document).foundation();
来初始化基础javascript组件.以下是我的主要内容
import 'foundation'
import $ from 'jquery';
import {Aurelia} from 'aurelia-framework';
export function configure(aurelia: Aurelia) {
aurelia.use
.standardConfiguration()
.developmentLogging();
aurelia.start().then(a => a.setRoot())
.then(a => {
// Initialize framework
$(document).foundation();
});
}
Run Code Online (Sandbox Code Playgroud)
其余代码只是默认导航到包含带有下拉列表的基础导航栏的简单页面
注意:即使将jquery列为dep,我也必须显式安装jquery.
我做了基础6的原始覆盖,显然做错了但它似乎在当时工作.但是,我已经发现当安装bootstrap时它将jquery放在github:components中,这似乎使得jquery不必显式安装.所以当时一切似乎都很好.
要重现只使用aurelia骨架并添加一个带有基础控件的页面,添加上面的$(document).foundation()
我试图根据这个答案以表格格式显示 json 数据。每次我运行这个,它都会显示这个错误Line 15: '$' is not defined no-undef
。我在第 15 行开始 ajax 调用。我尝试 const $ = window.$;
在代码顶部添加,但这并不能解决任何问题。
class App extends React.Component {
constructor(){
super()
this.state = {
data: []
}
}
componentDidMount() {
$.ajax({
url: "http://www.mocky.io/v2/5c3f2a6c3500004d00ec3789",
type: "GET",
dataType: 'json',
ContentType: 'application/json',
success: function(data) {
this.setState({data: data});
}.bind(this),
error: function(jqXHR) {
console.log(jqXHR);
}.bind(this)
})
}
render() {
return (
<table>
<tbody>{this.state.data.map(function(item, key) {
return (
<tr key = {key}>
<td>{item.name}</td>
<td>{item.post}</td>
<td>{item.country}</td>
<td>{item.contact}</td>
</tr>
) …
Run Code Online (Sandbox Code Playgroud)