1.安装jQuery

npm i jquery -S

2.修改webpack的配置文件

文件目录及名称:build/webpack.base.conf.js

注释代码为修改部分

'use strict'
const path = require('path')
const utils = require('./utils')
const config = require('../config')
const vueLoaderConfig = require('./vue-loader.conf')
const webpack = require('webpack') //这里引入webpack function resolve (dir) {
return path.join(__dirname, '..', dir)
} module.exports = {
context: path.resolve(__dirname, '../'),
entry: {
app: './src/main.js'
},
output: {
path: config.build.assetsRoot,
filename: '[name].js',
publicPath: process.env.NODE_ENV === 'production'
? config.build.assetsPublicPath
: config.dev.assetsPublicPath
},
resolve: {
extensions: ['.js', '.vue', '.json'],
alias: {
'vue$': 'vue/dist/vue.esm.js',
'@': resolve('src'), // 如果是自己下载的jq文件,则用下面方式修改为存放目录
// 'jquery': path.resolve(__dirname, '../src/assets/libs/jquery/jquery.min'),
// 如果使用NPM安装的jQuery,则直接引入即可
'jquery': 'jquery'
}
},
module: {
rules: [
{
test: /\.vue$/,
loader: 'vue-loader',
options: vueLoaderConfig
},
{
test: /\.js$/,
loader: 'babel-loader',
include: [resolve('src'), resolve('test'), resolve('node_modules/webpack-dev-server/client')]
},
{
test: /\.(png|jpe?g|gif|svg)(\?.*)?$/,
loader: 'url-loader',
options: {
limit: 10000,
name: utils.assetsPath('img/[name].[hash:7].[ext]')
}
},
{
test: /\.(mp4|webm|ogg|mp3|wav|flac|aac)(\?.*)?$/,
loader: 'url-loader',
options: {
limit: 10000,
name: utils.assetsPath('media/[name].[hash:7].[ext]')
}
},
{
test: /\.(woff2?|eot|ttf|otf)(\?.*)?$/,
loader: 'url-loader',
options: {
limit: 10000,
name: utils.assetsPath('fonts/[name].[hash:7].[ext]')
}
}
]
},
node: {
// prevent webpack from injecting useless setImmediate polyfill because Vue
// source contains it (although only uses it if it's native).
setImmediate: false,
// prevent webpack from injecting mocks to Node native modules
// that does not make sense for the client
dgram: 'empty',
fs: 'empty',
net: 'empty',
tls: 'empty',
child_process: 'empty'
},
//在最后添加一个plugins配置
plugins: [
new webpack.ProvidePlugin({
$: "jquery",
jQuery: "jquery"
})
],
}

在组件中使用jquery

<script>
//引入jquery就可以使用了
import $ from 'jquery'
export default {
name: 'HelloWorld',
data () {
return {
msg: 'Welcome to Your Vue.js App'
}
},
created(){
//已经能打印出来了
console.log($)
}
}
</script>

最新文章

  1. 被忽略的js细节
  2. 注册表法修改IE8安全级别的方法
  3. history介绍及bash命令快速调用
  4. 【转】移动端input输入placeholder垂直不居中
  5. 下载模板,上传EXCEL
  6. Windows server 2012 各版本 激活方法
  7. zoj 3870
  8. Linux - 进程间通信 - 命名管道
  9. string.prototype.replace 和正则表达式
  10. SM干货篇:你应该具备的提问技巧!
  11. Storm入门(五)Twitter Storm如何保证消息不丢失
  12. pycharm pip安装包
  13. 第十二届GOPS全球运维大会2019深圳站即将开幕
  14. JAVA中解决Filter过滤掉css,js,图片文件等问题
  15. 77 Linux commands and utilities you&#39;ll actually use
  16. I帧、P帧、B帧、GOP、IDR 和PTS, DTS之间的关系
  17. es6 常用总结
  18. UVALive - 3266 (贪心) 田忌赛马
  19. JAVA-数据库之添加记录
  20. sql注入学习心得与sqlmap使用心得

热门文章

  1. (转)打开Mac OSX原生的NTFS功能
  2. mount: you must specify the filesystem type
  3. 洛谷P3834【模板】可持久化线段树 1(主席树)
  4. 廖雪峰Java11多线程编程-3高级concurrent包-9Fork_Join
  5. js 类数组转化数组
  6. 解析Request和Response
  7. ValueError: Variable conv1/weights already exists.
  8. 史上最贵域名诞生!360斥资1700万美元买360.com
  9. 使用XPath查询带有命名空间(有xmlns)的XML(转)
  10. kafka一些问题点的分析