Pitfalls encountered in practical Vue projects and solutions
Pit 1. Resource loading 404 problem occurs when accessing index.html after packaging with webpack
##Solution Solution : In index.js in config, the level of the assetsPublicPath attribute in the build object needs to be adjusted from '/' to './'
1 build: { 2 env: require('./prod.env'), 3 index: path.resolve(__dirname, '../dist/index.html'), 4 assetsRoot: path.resolve(__dirname, '../dist'), 5 assetsSubDirectory: 'static', 6 assetsPublicPath: './', 7 productionSourceMap: false,12 productionGzip: false,13 productionGzipExtensions: ['js', 'css'],18 bundleAnalyzerReport: process.env.npm_config_report19 }
1 dev: { 2 env: require('./dev.env'), 3 port: 8080, 4 autoOpenBrowser: true, 5 assetsSubDirectory: 'static', 6 assetsPublicPath: '/', 7 proxyTable: {}, 8 // CSS Sourcemaps off by default because relative paths are "buggy" 9 // with this option, according to the CSS-Loader README10 // ()11 // In our experience, they generally work as expected,12 // just be aware of this issue when enabling this option.13 cssSourceMap: false14 }
Reason:
The static folder of the development environment is based on The root directory, so use'/' directly. For example, this format: http://localhost:8080/static/img/logo.png.
Everyone should know that webpack packaging will automatically package the static folder. By default, a dist folder will be generated as the root directory of the production environment file, and the static folder will be generated in dist. So the generated format should be http://localhost:8080/dist/static/img/logo.png. It is not based on the root directory, so ‘/’ The corresponding resource must not be found.
Introduce the meaning of these attributes: assetsRoot: The target folder path of webpack output assetsSubDirectory: The second level of webpack compilation output Folder assetsPublicPath: The release path of webpack compiled output, for example: /eat in www.woshichihuo.com/eat is this pathPit 2. Use webpack After packaging, a white screen appears when accessing index.html locally, but the resources are loaded normally
Solution: Do not set the routing setting mode to history mode. The default is still hash. In the index.js file under the router folder.
1 const router = new Router({2 // mode: 'history',3 routes: [4 index,5 home6 ]7 })
The above is the detailed content of Pitfalls encountered in practical Vue projects and solutions. For more information, please follow other related articles on the PHP Chinese website!

Hot AI Tools

Undresser.AI Undress
AI-powered app for creating realistic nude photos

AI Clothes Remover
Online AI tool for removing clothes from photos.

Undress AI Tool
Undress images for free

Clothoff.io
AI clothes remover

AI Hentai Generator
Generate AI Hentai for free.

Hot Article

Hot Tools

Notepad++7.3.1
Easy-to-use and free code editor

SublimeText3 Chinese version
Chinese version, very easy to use

Zend Studio 13.0.1
Powerful PHP integrated development environment

Dreamweaver CS6
Visual web development tools

SublimeText3 Mac version
God-level code editing software (SublimeText3)

Hot Topics



Share the simple and easy-to-understand PyCharm project packaging method. With the popularity of Python, more and more developers use PyCharm as the main tool for Python development. PyCharm is a powerful integrated development environment that provides many convenient functions to help us improve development efficiency. One of the important functions is project packaging. This article will introduce how to package projects in PyCharm in a simple and easy-to-understand way, and provide specific code examples. Why package projects? Developed in Python

Fermat's last theorem, about to be conquered by AI? And the most meaningful part of the whole thing is that Fermat’s Last Theorem, which AI is about to solve, is precisely to prove that AI is useless. Once upon a time, mathematics belonged to the realm of pure human intelligence; now, this territory is being deciphered and trampled by advanced algorithms. Image Fermat's Last Theorem is a "notorious" puzzle that has puzzled mathematicians for centuries. It was proven in 1993, and now mathematicians have a big plan: to recreate the proof using computers. They hope that any logical errors in this version of the proof can be checked by a computer. Project address: https://github.com/riccardobrasca/flt

Title: Learn more about PyCharm: An efficient way to delete projects. In recent years, Python, as a powerful and flexible programming language, has been favored by more and more developers. In the development of Python projects, it is crucial to choose an efficient integrated development environment. As a powerful integrated development environment, PyCharm provides Python developers with many convenient functions and tools, including deleting project directories quickly and efficiently. The following will focus on how to use delete in PyCharm

PyCharm is a powerful Python integrated development environment that provides a wealth of development tools and environment configurations, allowing developers to write and debug code more efficiently. In the process of using PyCharm for Python project development, sometimes we need to package the project into an executable EXE file to run on a computer that does not have a Python environment installed. This article will introduce how to use PyCharm to convert a project into an executable EXE file, and give specific code examples. head

How to Make a GroceryList on iPhone in iOS17 Creating a GroceryList in the Reminders app is very simple. You just add a list and populate it with your items. The app automatically sorts your items into categories, and you can even work with your partner or flat partner to make a list of what you need to buy from the store. Here are the full steps to do this: Step 1: Turn on iCloud Reminders As strange as it sounds, Apple says you need to enable reminders from iCloud to create a GroceryList on iOS17. Here are the steps for it: Go to the Settings app on your iPhone and tap [your name]. Next, select i

PHP Practice: Code Example to Quickly Implement the Fibonacci Sequence The Fibonacci Sequence is a very interesting and common sequence in mathematics. It is defined as follows: the first and second numbers are 0 and 1, and from the third Starting with numbers, each number is the sum of the previous two numbers. The first few numbers in the Fibonacci sequence are 0,1,1.2,3,5,8,13,21,...and so on. In PHP, we can generate the Fibonacci sequence through recursion and iteration. Below we will show these two

PyCharm is a powerful Python integrated development environment (IDE) that provides rich functions to help developers write and manage Python projects more efficiently. In the process of developing projects using PyCharm, sometimes we need to delete some projects that are no longer needed to free up space or clean up the project list. This article will detail how to delete projects in PyCharm and provide specific code examples. How to delete a project Open PyCharm and enter the project list interface. In the project list,

IDEA (IntelliJIDEA) is a powerful integrated development environment that can help developers develop various Java applications quickly and efficiently. In Java project development, using Maven as a project management tool can help us better manage dependent libraries, build projects, etc. This article will detail the basic steps on how to create a Maven project in IDEA, while providing specific code examples. Step 1: Open IDEA and create a new project Open IntelliJIDEA
