public/index.html
文件中通过 `
标签引入。
`
html,,,,,,Vue App,,,,,,,,,,,,
“
1、添加CDN地址到index.html:在public/index.html文件的<head>标签中添加你需要的CDN地址,引入Bootstrap和jQuery库:
代码 | 说明 |
|
引入Bootstrap的CSS样式表 |
|
引入jQuery库 |
2、在Vue组件中使用:在上述方法中引入的库可以直接在Vue组件中使用,在一个简单容器组件中使用Bootstrap的类:
代码 | 说明 |
|
使用Bootstrap的container类 |
|
|
|
1、动态加载脚本:在Vue组件的mounted生命周期钩子中,使用createElement方法动态加载脚本,动态加载jQuery:
| 代码 | 说明 |
| –| –|
|<template> <div> <h1>Dynamic Script Loading</h1> </div> </template>
|
| `<script> export default { mounted() { this.loadScript("https://code.jquery.com/jquery-3.3.1.min.js", () => { console.log("jQuery loaded dynamically!"); $(document).ready(function() { console.log("jQuery is ready!"); }); }); }, methods: { loadScript(src, callback) { const script = document.createElement("script"); script.type = "text"