在vue-cli项目中使用bootstrap

1.安装插件

npm install jquery --save
npm install bootstrap --save
npm install popper.js --save

2.配置webpack.base.conf.js

//在顶部添加
const webpack = require('webpack')

//在module.exports = {}末尾添加下面代码
module.exports = {
...
plugins: [
    new webpack.ProvidePlugin({
      $: "jquery",
      jQuery: "jquery"
    })
  ]
}

3.在main.js中导入

import $ from 'jquery'
import 'bootstrap'
import 'bootstrap/dist/css/bootstrap.min.css'
import 'bootstrap/dist/js/bootstrap.min'

4.测试jquery

//在vue文件中添加测试代码

<script>
$(function () {
  alert('jquery!')
})

export default {
  name: 'App'
}
</script>

5.测试bootstrap

<button type="button" class="btn btn-success">bootstrap测试</button>

猜你喜欢

转载自www.cnblogs.com/strawberry-zyyyy/p/11600287.html