最新下载
热门教程
- 1
- 2
- 3
- 4
- 5
- 6
- 7
- 8
- 9
- 10
在vue项目中,将juery设置为全局变量的方法
时间:2022-06-25 15:36:51 编辑:袖梨 来源:一聚教程网
1.首先执行:npm install jQuery --save-dev,在package.json里加入jQuery。
2.修改build下的webpack.base.conf.js
方法一:
首先加入:
const webpack = require("webpack")
然后在module.exports 对象中加入:
plugins: [ new webpack.optimize.CommonsChunkPlugin('common.js'), new webpack.ProvidePlugin({ jQuery: "jquery", $: "jquery" }) ]
方法二:
先加入:
const webpack = require("webpack")
然后:
resolve: { extensions: ['.js', '.vue', '.json'], alias: { 'vue$': 'vue/dist/vue.esm.js', '@': resolve('src'), 'jquery': 'jquery' } },
最后:
plugins: [ new webpack.ProvidePlugin({ jQuery: "jquery", $: "jquery" }) ]
3.在app.vue中调用jquery
mounted: function() { console.log($); console.log($('#ss')[0].innerHTML); },
打印结果:
相关文章
- 2025年8月XRP将迎来什么? 08-02
- 《阴阳师》“超鬼王”阿修罗阵容推荐分享 08-02
- 《奇迹暖暖》饴蜜迎春套装怎么获得方法有哪些 08-02
- 怎么驱动矿机-矿机怎么打驱动 08-02
- 《空之要塞:启航》阵容角色搭配最强推荐 08-02
- 《重返未来1999》洞悉机制有什么 08-02