vue-cli引入 bootstarp 和 jquery

1. 安装扩展,popper.js不安装有时报错,所以一起装上吧

npm i bootstrap jquery popper.js --save-dev

 

2. 配置 /build/webpack.base.conf.js

 

// 第 1 行加入,如果有 'use strict' 则在第 2 行加
const webpack=require('webpack')

// module.exports 中添加
plugins: [
  new webpack.ProvidePlugin({
    $: "jquery",
    jQuery: "jquery",
    "windows.jQuery": "jquery"
  })
]

 

3. 引入 /src/main.js

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

4. 使用

<a class="btn btn-primary" @click="sendGetFn">GET请求</a>

 

5. 可以在 vue 中测试 jqeury 是否引入

mounted () {
    console.log($);
}

 

完整代码可以参考:https://git.lug.ustc.edu.cn/gechenpeng/axiostest.git

posted @ 2020-07-27 08:00  夣回  阅读(114)  评论(0)    收藏  举报