我也遇到了同样的问题,这就是我最终遇到的问题.但是,自从beta版发布以来,我没有使用Bootstrap alpha.
- 安装Bootstrap及其依赖项、jQuery和Popper.js:
npm install bootstrap@4.0.0-beta popper.js jquery --save-dev
- 编辑
/build/webpack.dev.conf.js
文件,为jQuery和Popper添加插件.js处理依赖关系(你可以在Bootstrap docs页中阅读更多相关内容):
plugins: [
// ...
new webpack.ProvidePlugin({
$: 'jquery',
jQuery: 'jquery',
'window.jQuery': 'jquery',
Popper: ['popper.js', 'default'],
// In case you imported plugins individually, you must also require them here:
Util: "exports-loader?Util!bootstrap/js/dist/util",
Dropdown: "exports-loader?Dropdown!bootstrap/js/dist/dropdown",
// ...
})
// ...
]
- 编辑
/src/main.js
将 bootstrap 导入应用程序的入口点:
import Vue from 'vue'
import App from './App'
import router from './router'
import 'bootstrap' // ←
- 编辑应用程序.vue文件的
<style>
部分,用于将Bootsrap导入应用程序的根css:
<template>
<div id="app">
<img src="./assets/logo.png">
<router-view></router-view>
</div>
</template>
<script>
export default {
name: 'app'
}
</script>
<style>
#app {
font-family: 'Avenir', Helvetica, Arial, sans-serif;
-webkit-font-smoothing: antialiased;
-moz-osx-font-smoothing: grayscale;
text-align: center;
color: #2c3e50;
margin-top: 60px;
}
@import'~bootstrap/dist/css/bootstrap.css'
</style>
- 从CLI运行Vue应用程序
npm start
我必须在#app selector之后添加@import规则,否则就会添加范围样式