如何在Laravel中包含Bootstrap-Vue

San*_*was 3 laravel vue.js bootstrap-vue

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

app.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);
}
Run Code Online (Sandbox Code Playgroud)

app.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"
    })
Run Code Online (Sandbox Code Playgroud)

Kar*_*ana 5

您可以仅通过node和npm来执行此操作。在系统中安装节点。然后从项目根目录打开终端,就像使用laravel来运行artisan命令一样。

当您打开终端时。只需运行

npm i bootstrap-vue // you can also give save falg to save in package.json file
Run Code Online (Sandbox Code Playgroud)

这里不是安装vue。因为如果您在resources目录中检查app.js文件,它已经安装在laravel中,并且在成功安装后可以将其导入到app.js中

import BootstrapVue from 'bootstrap-vue' //Importing

Vue.use(BootstrapVue) // Telling Vue to use this in whole application
Run Code Online (Sandbox Code Playgroud)

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

@import 'node_modules/bootstrap/scss/bootstrap';
@import 'node_modules/bootstrap-vue/src/index.scss';
Run Code Online (Sandbox Code Playgroud)

在app.scss中

完成所有配置设置后

npm run dev // webpack在这里工作

或者如果您正在生产中,则可以通过

npm run production