如何在 Laravel 中包含 Bootstrap-Vue

新手上路,请多包涵

如何将 Bootstrap Vue 安装/导入/包含到我的 laravel 项目中?我是 Vue 新手,我知道如何在 Vue JS 应用程序中安装,但如何添加它 laravel

应用程序.scss

 // Fonts
@import url("https://fonts.googleapis.com/css?family=Nunito");

// Variables
@import "variables";

// Bootstrap
@import "~bootstrap/scss/bootstrap";

@import "node_modules/bootstrap/scss/bootstrap";
@import "node_modules/bootstrap-vue/src/index.scss";

.navbar-laravel {
    background-color: #fff;
    box-shadow: 0 2px 4px rgba(0, 0, 0, 0.04);
}

应用程序.js

     /**
     * First we will load all of this project's JavaScript dependencies which
     * includes Vue and other libraries. It is a great starting point when
     * building robust, powerful web applications using Vue and Laravel.
     */

    require("./bootstrap")

    window.Vue = require("vue")

    import BootstrapVue from "bootstrap-vue" //Importing

    Vue.use(BootstrapVue) // Teslling Vue to use this whole application

    /**
    * The following block of code may be used to automatically register your
    * Vue components. It will recursively scan this directory for the Vue
    * components and automatically register them with their "basename".
    *
    * Eg. ./components/ExampleComponent.vue -> <example-component></example-component>
    */

    // const files = require.context('./', true, /\.vue$/i);
    // files.keys().map(key => Vue.component(key.split('/').pop().split('.')[0], files(key).default));

    Vue.component(
        "example-component",
        require("./components/ExampleComponent.vue").default
    )

    /**
    * Next, we will create a fresh Vue application instance and attach it to
    * the page. Then, you may begin adding components to this application
    * or customize the JavaScript scaffolding to fit your unique needs.
    */

    const app = new Vue({
        el: "#app"
    })

原文由 Santanu Biswas 发布,翻译遵循 CC BY-SA 4.0 许可协议

阅读 511
2 个回答

你可以通过 node 和 npm 简单地做到这一点。在您的系统中安装节点。然后像使用 laravel 一样从项目根目录打开终端以运行 artisan 命令。

当你打开终端。简单地运行

npm i bootstrap-vue // you can also give save falg to save in package.json file

这里我没有安装 vue 。因为如果你检查你的 app.js 文件,它已经安装在 laravel 中,在你的 resources 目录中,成功安装后你可以将它导入你的 app.js 通过

import BootstrapVue from 'bootstrap-vue' //Importing

Vue.use(BootstrapVue) // Telling Vue to use this in whole application

对于 css,您可以简单地导入它

@import 'node_modules/bootstrap/scss/bootstrap';
@import 'node_modules/bootstrap-vue/src/index.scss';

在 app.scss 中

所有配置设置运行后

npm run dev //这里webpack做它的工作

或者如果你在生产中,你可以通过

npm run production

原文由 Karan Sadana 发布,翻译遵循 CC BY-SA 4.0 许可协议

只需在文件夹中执行 npm i vue bootstrap-vue bootstrap 那里有 package.json 或手动更改 package.json。然后你必须添加到 ./resources/assets/js/bootstrap.js

 import Vue from 'vue'
import BootstrapVue from 'bootstrap-vue'

Vue.use(BootstrapVue)

原文由 Manu 发布,翻译遵循 CC BY-SA 4.0 许可协议

撰写回答
你尚未登录,登录后可以
  • 和开发者交流问题的细节
  • 关注并接收问题和回答的更新提醒
  • 参与内容的编辑和改进,让解决方法与时俱进
推荐问题