- 安裝插件
npm install jquery --save
npm install bootstrap --save
npm install popper.js --save
如果cli版本小於v3:
- 配置
webpack.base.conf.js
//在頂部添加
const webpack = require('webpack')
//在module.exports = {}末尾添加下面代碼
module.exports = {
...
plugins: [
new webpack.ProvidePlugin({
$: "jquery",
jQuery: "jquery"
})
]
}
但是在Vue-cli v3
的版本中需要使用下面的方法
在根目錄中添加文件vue.config.js
,然後寫入下面配置
const webpack = require('webpack')
module.exports = {
configureWebpack: {
plugins: [
new webpack.ProvidePlugin({
$: "jquery",
jQuery: "jquery"
})
]
}
}
-
main.js
中添加
import $ from 'jquery'
import 'bootstrap'
- 測試
jquery
//在vue文件中添加測試代碼
<script>
$(function () {
alert('234')
})
export default {
name: 'App'
}
</script>
- 測試
bootstrap
<template>
<div class="container">
<div class="row">
<div class="col-md-6">
<button class="btn btn-primary">測試按鈕</button>
</div>
</div>
</div>
</template>