search
HomeWeb Front-endJS TutorialHow to solve problems when deploying Vue projects to the server

This article mainly introduces the solution to the problem of deploying the Vue project to the server. The editor thinks it is quite good. Now I will share it with you and give it as a reference. Let’s follow the editor and take a look.

I believe that when many friends use the scaffolding installed by Vue-cli to develop, the project can run normally in the development environment, but after entering the production environment, after compilation and packaging , put it into the server, the project will not work properly, and problems such as blank pages or routing jumps 404 will appear. Don't panic if you encounter these problems. Correct configuration and simple cooperation of the backend can solve them.

How to package

Based on Vue-Cli, packaging is performed through npm run build

How to deploy

  1. The packaged resources based on Vue-Cli usually have a static directory and an index.html file in the dist directory. You can directly throw these two files to the server

  2. But sometimes, we will throw the dist file directly to the server

Problems that occur

  1. After packaging to the server, the problem of resource reference path appears

  2. After packaging to the server, the problem of blank page appears

  3. After being packaged to the server, the type of the imported css was intercepted and converted to "text/plain"

  4. After being packaged to the server, the problem of route refresh 404 occurred

The author below will tell you how to solve these problems based on the experience of compiling and packaging the Vue project to normal deployment of the server.

1. Front-end configuration:

① Router configuration--specify the route start (in development mode, the Vue project is placed in webpack and generated with nodeJs The root directory of the local server, but in the real server, the project will definitely not be placed in the root directory, so the base of the router must be specified)

router

Discuss with the backend in advance the server folder path for project deployment

②, compile and package configuration

Enter config --> index.js

build

③. Use npm run build for packaging. So far, all the configurations that the front-end can do have been completed.

2. Back-end configuration:

404 appears in route jump. The main reason is that the backend does not do any processing for this virtual front-end route. When the server cannot find the resource under the specified path, it can only return 404 to the client.

Solution (Apache): Rewrite url --- Rewrite the path in the server folder where the Vue project is located, for example:

leibo.group/pcMall/.... For leibo.group/pcMall/index.html

.hatccess

, enable allowoverride, url rewrite, and the backend can be solved in minutes

If it is another type of server

Please refer to https://router.vuejs.org/zh-cn/essentials/history-mode.html

Summary: In the single-page deployment server, it is actually more of a change in thinking, using front-end routing to control changes in user interface content. The above is some of the author's experience in the project deployment server. If there is anything inappropriate in the explanation, please point it out. !

The above is what I compiled for everyone. I hope it will be helpful to everyone in the future.

Related articles:

How to implement axios secondary encapsulation in vue

How to use audio components in WeChat mini programs

How to use the video component to play videos in the WeChat mini program

How to implement the download progress bar in the WeChat mini program

How to use the mobile phone number verification tool class PhoneUtils in javaScript

The above is the detailed content of How to solve problems when deploying Vue projects to the server. For more information, please follow other related articles on the PHP Chinese website!

Statement
The content of this article is voluntarily contributed by netizens, and the copyright belongs to the original author. This site does not assume corresponding legal responsibility. If you find any content suspected of plagiarism or infringement, please contact admin@php.cn
Vue常见面试题汇总(附答案解析)Vue常见面试题汇总(附答案解析)Apr 08, 2021 pm 07:54 PM

本篇文章给大家分享一些Vue面试题(附答案解析)。有一定的参考价值,有需要的朋友可以参考一下,希望对大家有所帮助。

5 款适合国内使用的 Vue 移动端 UI 组件库5 款适合国内使用的 Vue 移动端 UI 组件库May 05, 2022 pm 09:11 PM

本篇文章给大家分享5 款适合国内使用的 Vue 移动端 UI 组件库,希望对大家有所帮助!

vue中props可以传递函数吗vue中props可以传递函数吗Jun 16, 2022 am 10:39 AM

vue中props可以传递函数;vue中可以将字符串、数组、数字和对象作为props传递,props主要用于组件的传值,目的为了接收外面传过来的数据,语法为“export default {methods: {myFunction() {// ...}}};”。

手把手带你利用vue3.x绘制流程图手把手带你利用vue3.x绘制流程图Jun 08, 2022 am 11:57 AM

利用vue3.x怎么绘制流程图?下面本篇文章给大家分享基于 vue3.x 的流程图绘制方法,希望对大家有所帮助!

聊聊vue指令中的修饰符,常用事件修饰符总结聊聊vue指令中的修饰符,常用事件修饰符总结May 09, 2022 am 11:07 AM

本篇文章带大家聊聊vue指令中的修饰符,对比一下vue中的指令修饰符和dom事件中的event对象,介绍一下常用的事件修饰符,希望对大家有所帮助!

如何覆盖组件库样式?React和Vue项目的解决方法浅析如何覆盖组件库样式?React和Vue项目的解决方法浅析May 16, 2022 am 11:15 AM

如何覆盖组件库样式?下面本篇文章给大家介绍一下React和Vue项目中优雅地覆盖组件库样式的方法,希望对大家有所帮助!

通过9个Vue3 组件库,看看聊前端的流行趋势!通过9个Vue3 组件库,看看聊前端的流行趋势!May 07, 2022 am 11:31 AM

本篇文章给大家分享9个开源的 Vue3 组件库,通过它们聊聊发现的前端的流行趋势,希望对大家有所帮助!

react与vue的虚拟dom有什么区别react与vue的虚拟dom有什么区别Apr 22, 2022 am 11:11 AM

react与vue的虚拟dom没有区别;react和vue的虚拟dom都是用js对象来模拟真实DOM,用虚拟DOM的diff来最小化更新真实DOM,可以减小不必要的性能损耗,按颗粒度分为不同的类型比较同层级dom节点,进行增、删、移的操作。

See all articles

Hot AI Tools

Undresser.AI Undress

Undresser.AI Undress

AI-powered app for creating realistic nude photos

AI Clothes Remover

AI Clothes Remover

Online AI tool for removing clothes from photos.

Undress AI Tool

Undress AI Tool

Undress images for free

Clothoff.io

Clothoff.io

AI clothes remover

AI Hentai Generator

AI Hentai Generator

Generate AI Hentai for free.

Hot Article

R.E.P.O. Energy Crystals Explained and What They Do (Yellow Crystal)
2 weeks agoBy尊渡假赌尊渡假赌尊渡假赌
R.E.P.O. Best Graphic Settings
2 weeks agoBy尊渡假赌尊渡假赌尊渡假赌
R.E.P.O. How to Fix Audio if You Can't Hear Anyone
2 weeks agoBy尊渡假赌尊渡假赌尊渡假赌

Hot Tools

Dreamweaver Mac version

Dreamweaver Mac version

Visual web development tools

SublimeText3 Chinese version

SublimeText3 Chinese version

Chinese version, very easy to use

SAP NetWeaver Server Adapter for Eclipse

SAP NetWeaver Server Adapter for Eclipse

Integrate Eclipse with SAP NetWeaver application server.

Safe Exam Browser

Safe Exam Browser

Safe Exam Browser is a secure browser environment for taking online exams securely. This software turns any computer into a secure workstation. It controls access to any utility and prevents students from using unauthorized resources.

VSCode Windows 64-bit Download

VSCode Windows 64-bit Download

A free and powerful IDE editor launched by Microsoft