溫馨提示×

溫馨提示×

您好,登錄后才能下訂單哦!

密碼登錄×
登錄注冊×
其他方式登錄
點擊 登錄注冊 即表示同意《億速云用戶服務(wù)條款》

laravel8.0 + vue如何安裝

發(fā)布時間:2021-04-21 11:41:51 來源:億速云 閱讀:353 作者:小新 欄目:編程語言

這篇文章給大家分享的是有關(guān)laravel8.0 + vue如何安裝的內(nèi)容。小編覺得挺實用的,因此分享給大家做個參考,一起跟隨小編過來看看吧。

為什么要使用Vue

Vue是一款友好的、多用途且高性能的JavaScript框架,使用vue可以創(chuàng)建可維護性和可測試性更強的代碼庫,Vue允許可以將一個網(wǎng)頁分割成可復(fù)用的組件,每個組件都包含屬于自己的HTML、CSS、JavaScript,以用來渲染網(wǎng)頁中相應(yīng)的地方,所以越來越多的前端開發(fā)者使用vue。

                           

創(chuàng)建項目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]# 
執(zhí)行命令查看 node 版本
# ./node -v
v12.18.3[root@VM-0-4-centos bin]# 
截止目前為止表示node 已經(jīng)可用了, 下一步是要讓 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

任意目錄 任意用戶 執(zhí)行:[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('_', '-', 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('css/app.css') }}" rel="stylesheet">

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

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

安裝完成后,Vue組件和JS文件在resources/js目錄下;

入口文件resources/js/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').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('./', 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);
//Vue.component('example-component', require('./components/DemoComponent.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',
});

運行

npm run dev

實時編譯

現(xiàn)在的情況是,每改動一次Vue組件就要重新執(zhí)行npm run dev,這樣非常麻煩;

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

感謝各位的閱讀!關(guān)于“l(fā)aravel8.0 + vue如何安裝”這篇文章就分享到這里了,希望以上內(nèi)容可以對大家有一定的幫助,讓大家可以學(xué)到更多知識,如果覺得文章不錯,可以把它分享出去讓更多的人看到吧!

向AI問一下細(xì)節(jié)

免責(zé)聲明:本站發(fā)布的內(nèi)容(圖片、視頻和文字)以原創(chuàng)、轉(zhuǎn)載和分享為主,文章觀點不代表本網(wǎng)站立場,如果涉及侵權(quán)請聯(lián)系站長郵箱:is@yisu.com進行舉報,并提供相關(guān)證據(jù),一經(jīng)查實,將立刻刪除涉嫌侵權(quán)內(nèi)容。

AI