javascript - 如何在 Vue 组件中使用 Bootstrap?

标签 javascript html vue.js bootstrap-4

我在这两个地方放置了相同的 html(使用 Bootstrap 4.5.2)。

  1. index.html
  2. App.vue

在 index.html 中,Bootstrap 风格有效。在 App.vue 中,按钮之间的空格失效。我通过添加类 mr-1 来解决这个问题到按钮。如何避免在将普通 Bootstrap 放入组件时修复它?

我试过的(结果相同)

  1. 将官方 BootstrapCDN 代码添加到 index.html

  2. 将此添加到 main.js并安装模块

    import jQuery from "jquery";
    global.jQuery = jQuery;
    let Bootstrap = require("bootstrap");
    import "bootstrap/dist/css/bootstrap.css";
    
  3. <style> 中添加了这个App.vue 部分

    @import url('https://stackpath.bootstrapcdn.com/bootstrap/4.5.2/css/bootstrap.min.css');
    
  4. Momin的建议:

    在项目文件夹目录中安装所有内容

    npm install bootstrap jquery popper.js

    将此添加到 main.js: 的顶部

    import 'bootstrap'
    import 'bootstrap/dist/css/bootstrap.min.css'
    

最佳答案

如果您需要 Bootstrap,只需使用 BootsrapVue这为你做了繁重的工作。 如果您仍然愿意接受其他选择,Vuetifyjs是一个非常好的框架,可以提供很多东西。

关于javascript - 如何在 Vue 组件中使用 Bootstrap?,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/63638434/

相关文章:

javascript - 如何设置日期时间选择器的样式

jquery - .animate() 查询不工作

html - 导航栏上链接的 Bootstrap 间距

javascript - 使用 vuex mapGetters 迭代用户的状态 obj

javascript - 我可以使用计算属性来有条件地设置表格行的样式吗?

javascript - 如何修复支架上的绒毛?

javascript - 访问指令中的元素 "computed style"

javascript - 将特定于区域的日期格式设置为 dd-MMM-yyyy?

javascript - 与Vuex的双向绑定(bind)

javascript - 将类添加到 javascript 选择器?