How to set an alias for a custom path in Vue

How to set an alias for a custom path in Vue

How to configure custom path aliases in Vue

In our daily development, we often import some modules or components. If we use relative paths:

import uEditor from "../../../../../components/tools";

It will appear bloated and redundant. If there is a slight mistake in the reference, a -404 error will appear, which is not elegant. 404 errors will often occur. If the file changes, you need to find the change path one by one and modify it again, which is very troublesome. Versions above vue cli3 provide a file alias function in node_modules. However, it is still recommended to modify the node_modules code as little as possible unless there is a special requirement.

Create vue.config.js and write the configuration code

module.exports = {
    configureWebpack: {
        resolve: {
            alias: { //Configure alias, you need to recompile after modification to take effect 'assets': '@/assets',
                'common': '@/common',
                'components': '@/components',
                'network': '@/network',
                'views': '@/views',
            }
        }
    }
}

As shown below:

Note: If you use an alias in an HTML path, you need to prefix the reference with "~".

Other references in the document:

The above is the method that I introduced to you in Vue to set aliases for custom paths. I hope it will be helpful to you. I would also like to thank everyone for their support of the 123WORDPRESS.COM website!

You may also be interested in:
  • Implementation of Vue alias path prompt in vscode
  • How to configure Vue's path alias in vue.config.js
  • Detailed explanation of Vue CL3 configuration path alias
  • Use alias path to reference static image address in webpack+vue
  • How to implement aliasing paths in Vue

<<:  Use pure CSS to disable the a tag in HTML without JavaScript

>>:  Teach you the detailed process of using Docker to build the Chinese version of gitlab community

Recommend

MySQL uses events to complete scheduled tasks

Events can specify the execution of SQL code once...

Difference between MySQL update set and and

Table of contents Problem Description Cause Analy...

MySQL case when usage example analysis

First we create the database table: CREATE TABLE ...

mysql obtains statistical data within a specified time period

mysql obtains statistical data within a specified...

How to improve MySQL Limit query performance

In MySQL database operations, we always hope to a...

Detailed explanation of the solution to image deformation under flex layout

Flex layout is a commonly used layout method nowa...

More popular and creative dark background web design examples

Dark background style page design is very popular...

Example of how to enable Brotli compression algorithm for Nginx

Brotli is a new data format that can provide a co...

How to use CocosCreator object pool

Table of contents Preface: Specific operations St...

Install JDK8 in rpm mode on CentOS7

After CentOS 7 is successfully installed, OpenJDK...

Detailed explanation of the use of filter properties in CSS3

Recently, when I was modifying the intranet porta...

Mysql practical exercises simple library management system

Table of contents 1. Sorting function 2. Prepare ...

Detailed tutorial on installing Tomcat9 windows service

1. Preparation 1.1 Download the tomcat compressed...