一:终端控制台下载jquery
输入npm install jquery -s
,默认下载最新版本,你需要控制版本下载,可以在jquery后加@版本。
二:配置
打开build文件夹下的webpack.base.conf.js文件:
1、首行添加:const webpack=require(‘webpack’)
2、module.exports中添加:
plugins: [
new webpack.ProvidePlugin({
$: "jquery",
jQuery: "jquery",
jquery: "jquery",
"window.jQuery": "jquery"
})
],
三:在main文件中引入jquery即可
import $ from 'jquery'
四:效果
<template>
<div >
<p class="my-p">
哈哈
</p>
</div>
</template>
<script>
export default {
name: 'demo',
mounted () {
console.log('使用jquery ' + $('.my-p').text())
}
}
</script>