-
-
Notifications
You must be signed in to change notification settings - Fork 3.3k
[vue] 在vue项目中如何引入第三方库(比如jQuery)?有哪些方法可以做到? #320
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Comments
1、绝对路径直接引入 2 、在webpack中配置alias 3、在webpack中配置plugins |
一、绝对路径直接引入,全局可用 export default { 三、webpack中配置 alias,import 引入后再使用
在任意组件中,通过 import 的方式来使用 jquery 了 四、webpack 中配置 plugins,无需 import 全局可用
在项目中,就可以直接使用 $ 了。 |
<script src="https://cdn.bootcdn.net/ajax/libs/jquery/1.10.1/jquery.min.js"></script> |
直接引入最简单的方式是在index.html文件中通过<script>标签直接引入CDN提供的第三方库的URL。例如:
使用import导入如果项目使用了模块化的构建工具(如Vue CLI),可以使用import语句将第三方库作为模块导入。
然后,在需要使用第三方库的组件中,使用import语句导入并使用:
Vue插件形式引入:对于一些比较复杂的第三方库,可能需要将其封装成Vue插件,以便在Vue项目中更好地集成和使用。
在Vue的主入口文件(如main.js)中导入并使用该插件:
|
[vue] 在vue项目中如何引入第三方库(比如jQuery)?有哪些方法可以做到?
The text was updated successfully, but these errors were encountered: