首頁  >  文章  >  php框架  >  laravel8.0 + vue 安裝方法詳解

laravel8.0 + vue 安裝方法詳解

藏色散人
藏色散人轉載
2021-04-21 09:14:153174瀏覽

下面由laravel教學專欄跟大家介紹laravel8.0 vue 安裝,希望對需要的朋友有幫助!

建立專案laravel

composer create-project --prefer-dist laravel/laravel fl_app

composer install

php artisan key:generate

#安裝node

yum install wget
wget https://nodejs.org/dist/v12.18.3/node-v12.18.3-linux-x64.tar.xz#得到 一个包 node-v12.18.3-linux-x64.tar
 xz -d node-v12.18.3-linux-x64.tar.xz#得到一个目录 node-v12.18.3-linux-x64
 tar -xvf node-v12.18.3-linux-x64.tar
切换到node bin目录 一共有三个文件 node npm  npx 
src]# cd node-v12.18.3-linux-x64/bin/[root@VM-0-4-centos bin]# ll
total 47508-rwxr-xr-x 1 work work 48646656 Jul 22 23:00 node
lrwxrwxrwx 1 work work       38 Jul 22 23:00 npm -> ../lib/node_modules/npm/bin/npm-cli.js
lrwxrwxrwx 1 work work       38 Jul 22 23:00 npx -> ../lib/node_modules/npm/bin/npx-cli.js[root@VM-0-4-centos bin]# 
执行命令查看 node 版本
# ./node -v
v12.18.3[root@VM-0-4-centos bin]# 
截止目前为止表示node 已经可用了, 下一步是要让 node 命令全局可用

軟體連接

#
我的node 放在 /usr/local/src 目录下 
ln -s /usr/local/src/node-v12.18.3-linux-x64/bin/node /usr/bin/node
ln -s /usr/local/src/node-v12.18.3-linux-x64/bin/npm /usr/bin/npm
ln -s /usr/local/src/node-v12.18.3-linux-x64/bin/npx /usr/bin/npx

任意目录 任意用户 执行:[root@VM-0-4-centos ~]# node -v
v12.18.3[huipeng@VM-0-4-centos ~]$ node -v
v12.18.3表示完成
npm install
npm audit fix
npm audit fix npm audit fix --force npm audit
npm audit
npm install

改造laravel歡迎介面視圖resources/views/welcome.blade.php

<!DOCTYPE html>
<html lang="{{ str_replace(&#39;_&#39;, &#39;-&#39;, app()->getLocale()) }}">
   <head>
       <meta charset="utf-8">
       <meta name="viewport" content="width=device-width, initial-scale=1">

       <title>Laravel</title>

       <!--1、 引入支持 Bootstrap 的 CSS 样式文件 -->
       <link href="{{ asset(&#39;css/app.css&#39;) }}" rel="stylesheet">

   </head>
   <body>
     <div id="app">
         <div>
      <!-- 3、使用组件 -->
           <example-component></example-component>
         </div>
     </div>  

    <!-- 2、引入支持Vue框架和Vue组件的app.js文件 -->
     <script src="{{ asset(&#39;js/app.js&#39;) }}"></script>
   </body>
</html>

安裝完成後,Vue元件和JS檔案在resources/js目錄下;

入口檔resources/js/app.js檔

/**
 * First we will load all of this project&#39;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(&#39;./bootstrap&#39;);

window.Vue = require(&#39;vue&#39;).default;

/**
 * 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(&#39;./&#39;, true, /\.vue$/i)
// files.keys().map(key => Vue.component(key.split(&#39;/&#39;).pop().split(&#39;.&#39;)[0], files(key).default))

Vue.component(&#39;example-component&#39;, require(&#39;./components/ExampleComponent.vue&#39;).default);
//Vue.component(&#39;example-component&#39;, require(&#39;./components/DemoComponent.vue&#39;).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: &#39;#app&#39;,
});

執行

npm run dev

即時編譯

現在的情況是,每改動一次Vue元件要重新執行npm run dev,這樣非常麻煩;

可以使用npm run watch指令編譯前端資源,每改動一次就會自動進行重新編譯

相關推薦:最新的五個Laravel影片教學

#

以上是laravel8.0 + vue 安裝方法詳解的詳細內容。更多資訊請關注PHP中文網其他相關文章!

陳述:
本文轉載於:learnku.com。如有侵權,請聯絡admin@php.cn刪除