百科.dev
全部条目在线工具AI 编程趋势榜开源项目技术资讯提交条目
登录
< 返回工具列表
L

laravel-vue-cli-3

> 编程语言
开源

使用 Vue CLI 3 与 Laravel 的示例项目

841 stars0 点赞1 次浏览
访问官网GitHub

工具介绍

使用 Vue CLI 3 与 Laravel 的示例项目

Laravel + Vue CLI 3

此演示假设您通过 Valet 在 laracon.test 上服务此 Laravel 应用。如果您在不同的本地 URL 上服务 laravel 应用,请在 frontend/vue.config.js 中进行相应修改。

运行前端

bash
cd frontend
yarn # OR npm install
yarn serve # OR npm run serve

# build for production:
yarn build # OR npm run build

从头开始搭建框架的步骤

  1. 创建 Laravel 项目
bash
    laravel new my-project
    cd my-project

    # remove existing frontend scaffold
    rm -rf package.json webpack.mix.js yarn.lock resources/assets
    ```
2. 在 Laravel 应用中创建一个 Vue CLI 3 项目
``` sh
    vue create frontend
    # pick router
    ```
3. 配置 Vue 项目
创建 `frontend/vue.config.js`:
``` js
    module.exports = {
      // proxy API requests to Valet during development
      devServer: {
        proxy: 'http://laracon.test'
      },

      // output built static files to Laravel's public dir.
      // note the "build" script in package.json needs to be modified as well.
      outputDir: '../public',

      // modify the location of the generated HTML file.
      // make sure to do this only in production.
      indexPath: process.env.NODE_ENV === 'production'
        ? '../resources/views/index.blade.php'
        : 'index.html'
    }
    ```
编辑 `frontend/package.json`:
``` diff
    "scripts": {
      "serve": "vue-cli-service serve",
    - "build": "vue-cli-service build",
    + "build": "rm -rf ../public/{js,css,img} && vue-cli-service build --no-clean",
      "lint": "vue-cli-service lint"
    },
    ```
4. 为单页面应用程序配置 Laravel。
**routes/web.php**
``` php
    where('any', '.*');
    ```
**app/Http/Controllers/SpaController.php**
``` php
    <?php

    namespace App\Http\Controllers;

    use Illuminate\Http\Request;

    class SpaController extends Controller
    {
        public function index()
        {
            return view('index');
        }
    }
    ```

Issues· 0 开放

查看全部 Issues在 GitHub 打开

暂无开放 Issues,或尚未同步最近议题。

> 标签

PHP

暂无评论,来聊聊你的看法吧

> 工具信息

发布日期2026年8月1日
最后更新2026年9月17日
分类编程语言
定价开源

> 相关工具

T
TypeScript
JavaScript 的超集,为前端与全栈提供静态类型
P
Python
通用编程语言,广泛用于 Web、数据与 AI
G
Go
Google 推出的简洁高效系统语言