อันว่า jQuery เจเควียรี พี่แกอาวุธโสจนต้องบอกว่า เก่า แต่ยังเก๋าอยู่พอมาอยู่ในยุค TypeScript ก็มีบาง JavaScript ที่ยังต้องใช้บริการมันอยู่
- เพิ่ม jQuery โดย command
npm install @types/jquery jquery
- เปิดไฟล์ SourceCode/resources/js/app.ts
- เพิ่ม code
12345678910
//jQuery
import
$ from
"jquery"
;
declare global {
interface
Window {
$:
typeof
$;
}
}
window.$ = $;
- ใช้ command
npm run dev
- ทดสอบโดยใส่
1 2 3 4 5 6 | < script > $(document).ready(function() { // Your jQuery code here console.log("Document is ready!"); }); </ script > |
อธิบาย
บรรทัดที่ 4 จะทำให้สามารถใช้ $ ในหน้าเพจ