To use Laravel's local development server with Vue.js, you can follow these general steps:
Create a New Laravel Project:
Install Laravel using Composer:
bashcomposer create-project --prefer-dist laravel/laravel your-project-name
Install Vue.js:
Laravel comes with Laravel Mix, which is a wrapper for Webpack. You can use it to easily integrate Vue.js into your Laravel project. By default, Laravel includes Vue.js and Axios. Ensure your package.json
file has these dependencies:
json"dependencies": {
"axios": "^0.21",
"bootstrap": "^4.0.0",
"cross-env": "^5.1",
"jquery": "^3.2",
"laravel-mix": "^6.0.6",
"lodash": "^4.17.19",
"popper.js": "^1.12",
"vue": "^2.5.7"
}
Install the dependencies:
bashnpm install
Create Vue Components:
resources/js/components
directory.Compile Assets:
Laravel Mix will compile your assets and place them in the public
directory. Run:
bashnpm run dev
This command will run the Webpack Mix to compile your assets.
Setup Routes:
Create routes in your Laravel application to render your Vue components. For example, in your web.php
file:
phpuse Illuminate\Support\Facades\Route;
Route::get('/', function () {
return view('welcome');
});
Route::get('/vue', function () {
return view('vue');
});
Here, the 'vue' route would correspond to a Blade view that includes your Vue component.
Create Blade Views:
Create Blade views (e.g., resources/views/vue.blade.php
) to render your Vue components:
html<!DOCTYPE html>
<html lang="en">
<head>
<meta charset="utf-8">
<meta name="viewport" content="width=device-width, initial-scale=1, shrink-to-fit=no">
<title>Laravel Vue</title>
<link rel="stylesheet" href="{{ mix('css/app.css') }}">
</head>
<body>
<div id="app">
<!-- Your Vue component goes here -->
<example-component></example-component>
</div>
<script src="{{ mix('js/app.js') }}"></script>
</body>
</html>
Run Laravel Development Server:
Start the Laravel development server:
bashphp artisan serve
This will start the server at http://localhost:8000
by default.
Access Your Application:
http://localhost:8000/vue
(or the route you defined) to see your Laravel application with Vue.js components.Remember to update your routes, views, and components according to your project's requirements. This is a basic setup, and you can customize it further based on your specific needs.