Network Security Internet Technology Development Database Servers Mobile Phone Android Software Apple Software Computer Software News IT Information

In addition to Weibo, there is also WeChat

Please pay attention

WeChat public account

Shulou

How to deploy vue in Laravel

2025-01-19 Update From: SLTechnology News&Howtos shulou NAV: SLTechnology News&Howtos > Development >

Share

Shulou(Shulou.com)06/02 Report--

This article mainly introduces "how to deploy vue in Laravel". In daily operation, I believe many people have doubts about how to deploy vue in Laravel. The editor consulted all kinds of materials and sorted out simple and easy-to-use operation methods. I hope it will be helpful to answer the doubts of "how to deploy vue in Laravel"! Next, please follow the editor to study!

Environmental deployment of Laravel+vue

This tutorial introduces the deployment of vue in Laravel, which includes some basic scaffolding to make it easier to start writing modern JavaScript using the Vue library. Vue provides expressive API for building powerful JavaScript applications using components. We can use Laravel Mix to easily compile the JavaScript component into a browsable JavaScript file.

Create laravel

First, you have to have a composer, and then you have a laravel. Run the command composer create-project-- prefer-dist laravel/laravel blog to create a new laravel project.

Hello world!

Open the command line and enter cd blog in your project

Before the start, due to a variety of reasons, npm as a foreign node warehouse installation tool, operation may occur slow and other problems, generally recommended to use taobao source for acceleration, followed by the same suffix code, download project default dependence, the code is as follows.

Npm install-- registry= https://registry.npm.taobao.org

Download the vue routing management code as follows.

Npm install vue-router-save-dev

Create a new HelloComponent.vue custom component file in / resources/assets/js/components with the following code.

Hello World! Export default {data () {return {}

Create a new folder router under / resources/assets/js, create a new hello.js in it, and map the hello route to the newly created HellowComponent component through nested routing configuration, as shown below.

Import Vue from 'vue'import VueRouter from' vue-router'Vue.use (VueRouter) export default new VueRouter ({saveScrollPosition: true, routes: [{name: "hello", path:'/', component: resolve = > void (require (['.. / components/HelloComponent.vue'], resolve)},]})

Create a new hello.vue under the current laravel project / resources/assets/js as the main interface and nest the routing view as follows.

Hello export default {data () {return {}

Then create a new hello.js under / resources/assets/js, as follows.

Require ('. / bootstrap'); window.Vue = require ('vue'); import Vue from' vue'import App from'. / hello.vue'import router from'. / router/hello.js'const app = new Vue ({el:'# app', router, render: h = > h (App)})

Create a new hello.blade.php under / resources/views, as shown below.

Hello

Add a new route to / resources/routes/web.php with the following code.

Route::view ('/ hello','/hello')

Modify webpack.mix.js, the code is as follows.

Mix.js ('resources/assets/js/app.js',' public/js') .js ('resources/assets/js/hello.js',' public/js') .extract (['vue', "vue-router", "axios"]) .sass (' resources/assets/sass/app.scss', 'public/css')

After saving, execute npm run watch under the project directory on the command line to recompile

You can enter php artisan serve under this project directory on the command line and visit http://127.0.0.1:8000/hello to see the effect.

Route::view and Route::redirect methods have been added to laravel5.5. Routes up to 5. 4 can be written as Route::get ('/ hello', function () {return view ('hello');})

At this point, the study on "how to deploy vue in Laravel" is over. I hope to be able to solve your doubts. The collocation of theory and practice can better help you learn, go and try it! If you want to continue to learn more related knowledge, please continue to follow the website, the editor will continue to work hard to bring you more practical articles!

Welcome to subscribe "Shulou Technology Information " to get latest news, interesting things and hot topics in the IT industry, and controls the hottest and latest Internet news, technology news and IT industry trends.

Views: 0

*The comments in the above article only represent the author's personal views and do not represent the views and positions of this website. If you have more insights, please feel free to contribute and share.

Share To

Development

Wechat

© 2024 shulou.com SLNews company. All rights reserved.

12
Report