加入收藏 | 设为首页 | 会员中心 | 我要投稿 李大同 (https://www.lidatong.com.cn/)- 科技、建站、经验、云计算、5G、大数据,站长网!
当前位置: 首页 > 综合聚焦 > 服务器 > 安全 > 正文

twitter-bootstrap – 将引导程序添加到Vue CLI项目

发布时间:2020-12-18 00:23:12 所属栏目:安全 来源:网络整理
导读:我是Vue和webpack的新手,我很难搞清楚如何导入东西. 我通过vue init创建了一个新的Vue项目我添加了bootstrap 4 with yarn add bootstrap@4.0.0-alpha.6 在main.js中我尝试导入bootstrap和jquery: import Vue from 'vue';import jQuery from 'jquery';import
我是Vue和webpack的新手,我很难搞清楚如何导入东西.

我通过vue init创建了一个新的Vue项目我添加了bootstrap 4 with yarn add bootstrap@4.0.0-alpha.6

在main.js中我尝试导入bootstrap和jquery:

import Vue from 'vue';
import jQuery from 'jquery';
import bootstrap from 'bootstrap';
import App from './App';
import router from './router';

但我得到:

Uncaught Error: Bootstrap’s JavaScript requires jQuery. jQuery must be
included before Bootstrap’s JavaScript.

window.jQuery = window.$= $;不起作用

最后,我在哪里以及如何加载Sass以便整个应用程序都可以使用它?

解决方法

我遇到了同样的问题,这是我最终的结果,但是我没有使用Bootstrap alpha,因为beta已经发布了.

>安装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文档中阅读更多关于here的信息):

插件:[

new webpack.ProvidePlugin({
$:’jquery’,
jQuery:’jquery’,
‘window.jQuery’:’jquery’,
Popper:[‘popper.js’,’default’],
//如果你单独导入插件,你还必须在这里要求它们:
Util:“exports-loader?Util!bootstrap / js / dist / util”,
下拉列表:“exports-loader?Dropdown!bootstrap / js / dist / dropdown”,

})

]
>编辑/src/main.js将Bootstrap导入应用程序的入口点:

从’vue’导入Vue
从’./App’导入应用程序
从’./router’导入路由器
导入’bootstrap’
>编辑App.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开始

I had to add the @import rule after the #app selector,otherwise the scoped styling would be canceled out by the Bootstrap import. I think there is a better way to do this so I will update my answer once I figure it out.

(编辑:李大同)

【声明】本站内容均来自网络,其相关言论仅代表作者个人观点,不代表本站立场。若无意侵犯到您的权利,请及时与联系站长删除相关内容!

    推荐文章
      热点阅读