ฉันกำลังพยายามแสดงปุ่มที่มีระลอกคลื่นโดยใช้ Material Design Lite แต่ได้รับข้อผิดพลาดต่อไปนี้:
app.js:3 Uncaught (ตามสัญญา) TypeError: $ ไม่ใช่ฟังก์ชัน(…)
ไฟล์ 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>
`;
}
}
ฐาน 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';
}
}
console.log($)
? - person Michał Perłakowski   schedule 29.11.2016app.js
และเหลือเพียงimport $ from 'jquery'; console.log($);
- person Michał Perłakowski   schedule 29.11.2016import 'jquery'
ไหม - person sdgluck   schedule 29.11.2016