2
我試圖用料設計精簡版,但收到以下錯誤顯示與紋波按鈕:
app.js:3 Uncaught (in promise) TypeError: $ is not a function(…)
HTML文件:
<body>
<script>
System.paths['jquery'] = './node_modules/jquery/dist/jquery.js';
System.import('src/app.js');
</script>
</body>
app.js:
import $ from 'jquery';
import {Button} from './ui/button.js';
let b=new Button('click me');
b.appendToElement($('body'));
button.js:
import {BaseElement} from './base-element.js';
export class Button extends BaseElement {
constructor(title) {
super();
this.title = title;
}
getElementString() {
return `
<button class="mdl-button mdl-js-button mdl-button--raised mdl-js-ripple-effect mdl-button--accent"
style="">
${this.title}
</button>
`;
}
}
基element.js:
import $ from 'jquery';
export class BaseElement {
constructor() {
this.element = null; // jQuery object
}
appendToElement(el) {
this.createElement();
el.append(this.element);
}
createElement() {
let s = this.getElementString();
this.element = $(s);
}
getElementString() {
throw 'Please override getElementString() in BaseElement';
}
}
它描述你的jquery沒有導入你的文件 –
@SanjayPatel是我的語法錯誤還是nythng其他? –
當你使用console.log($)'時,你會得到什麼? –