登录  /  注册
首页 > php框架 > Laravel > 正文

laravel8.0 + vue 安装方法详解

藏色散人
发布: 2021-04-21 09:14:15
转载
2957人浏览过

下面由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中文网其它相关文章!

智能AI问答
PHP中文网智能助手能迅速回答你的编程问题,提供实时的代码和解决方案,帮助你解决各种难题。不仅如此,它还能提供编程资源和学习指导,帮助你快速提升编程技能。无论你是初学者还是专业人士,AI智能助手都能成为你的可靠助手,助力你在编程领域取得更大的成就。
来源:learnku网
本文内容由网友自发贡献,版权归原作者所有,本站不承担相应法律责任。如您发现有涉嫌抄袭侵权的内容,请联系admin@php.cn
作者最新文章
最新问题
热门教程
更多>
最新下载
更多>
网站特效
网站源码
网站素材
前端模板
关于我们 免责申明 意见反馈 讲师合作 广告合作 最新更新
php中文网:公益在线php培训,帮助PHP学习者快速成长!
关注服务号 技术交流群
PHP中文网订阅号
每天精选资源文章推送
PHP中文网APP
随时随地碎片化学习
PHP中文网抖音号
发现有趣的

Copyright 2014-2024 https://www.php.cn/ All Rights Reserved | php.cn | 湘ICP备2023035733号