我正在尝试使用 Material Design lite 显示一个带有波纹的按钮,但出现以下错误:
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>
应用程序.js:
import $ from 'jquery';
import {Button} from './ui/button.js';
let b=new Button('click me');
b.appendToElement($('body'));
按钮.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>
`;
}
}
基本元素.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';
}
}