Laravel7.X에서 Vue입니다.js 설치 시도

npm 시작


npmrunwatch로 다음 오류 메시지 출력
terminal
'cross-env' is not recognized as an internal or external command,
operable program or batch file.
이 링크를 참고하여 해결하세요.
https://stackoverflow.com/questions/45034581/laravel-5-4-cross-env-is-not-recognized-as-an-internal-or-external-command

부트스트랩-Vue 구현을 위한 환경 구축


본 문서 구현 참조(https://bootstrap-vue.js.org/docs)
npm에bootstrap-vue 설치
terminal
# With npm
npm install vue bootstrap-vue bootstrap
bootstrap-vue 가져오기
resources\js\bootstrap.js
import Vue from 'vue'
import { BootstrapVue, IconsPlugin } from 'bootstrap-vue'
import 'bootstrap/dist/css/bootstrap.css'
import 'bootstrap-vue/dist/bootstrap-vue.css'
Vue용 js 및 Blade 구성
resources\js\components\example.vue
<template>
    <div class="container">
        <div class="row justify-content-center">
            <div class="col-md-8">
                <div class="card">
                    <div class="card-header">{{ greeting }}</div>
                    <div class="card-body">
                        I'm an example component.
                    </div>
                </div>
            </div>
        </div>
    </div>
</template>
<script>
    module.exports = {
        data: function() {
            return {
                greeting: 'hello'
            }
        }
    }
</script>
resources\js\app.js
require('./bootstrap');

// Bootstrap-vueの実装
import Vue from 'vue'
import { BootstrapVue, IconsPlugin } from 'bootstrap-vue'

import 'bootstrap/dist/css/bootstrap.css'
import 'bootstrap-vue/dist/bootstrap-vue.css'

window.Vue = require('vue');
import ExampleComponent from './components/example.vue'
Vue.component('example-component', ExampleComponent)

new Vue({
    el: '#app'
});
resources\views\welcome.blade.php
<!DOCTYPE html>
<html lang="{{ str_replace('_', '-', app()->getLocale()) }}">
    <head>
        <meta charset="utf-8">
        <meta name="viewport" content="width=device-width, initial-scale=1">
        <link rel="stylesheet" href="{{ mix('/css/app.css') }}">
        <title>Laravel</title>
    </head>
    <body>
        <div id="app">
            <example-component></example-component>
        </div>
    </body>
    <script src="{{ mix('/js/app.js') }}"></script>
</html>
npm와apache 시작
npm 시작
npm run watch

 DONE  Compiled successfully in 8718ms                                                                                                                                                                                                           22:31:38
       Asset      Size   Chunks             Chunk Names
/css/app.css   0 bytes  /js/app  [emitted]  /js/app
  /js/app.js  3.04 MiB  /js/app  [emitted]  /js/app
artisan 명령으로 서버 시작
php artisan serve
Laravel development server started: http://127.0.0.1:8000
확인 결과 화면

OK

Bootstrap-vue 구현


네비게이션 표시줄에서 구현
제작 구성 요소 역시 앱입니다.js로 정의
resources\js\app.js
import NavVar from './components/navbar.vue'
Vue.component('navigation-bar', NavVar)
태그로 정의된 어셈블리 생성하기
resources\views\welcome.blade.php
<div id="app">
    <navigation-bar></navigation-bar>
    <example-component></example-component>
</div>

좋은 웹페이지 즐겨찾기