


The difference between custom path alias assets and static folders in vue-cli
Write in front:
This is a brief introduction to several small knowledge points of vue-cli. It is suitable for students who are new to vue-cli scaffolding and who do not know much about it. , the big guys took a detour. Friends in need can make a reference. If you like it, you can like it or follow it. I hope it can help everyone.
Static resource processing:
The difference between assets and static folders
I believe many people know that vue-cli has two places to place static resources, which are ## Many people may not be clear about the difference between the #src/assets folder and the
static folder.
The files in the assets directory will be processed and parsed into module dependencies by webpack, and only relative path forms are supported. For example, in
and
background: url(./logo.png), "./logo. png" is a relative resource path that will be parsed by Webpack as a module dependency. Files in the
static/ directory will not be processed by Webpack: they will be copied directly to the final packaging directory (default is dist/static). These files must be referenced using absolute paths, which are determined through the build.assetsPublicPath and build.assetsSubDirectory connections in the config.js file.
Any files placed in static/ need to be referenced in the form of absolute paths: /static/[filename]. In our actual development, in general:static holds files that will not change and assets holds files that may change.
How to reference images in js dataBecause webpack will reference images as modules, you need to use require to reference images in js, and you cannot directly use strings. form.js部分: data () { return { imgUrl: '图片地址',//错误写法 imgUrl: require('图片地址')//正确的写法 } } template部分: img标签形式: <img src="/static/imghwm/default1.png" data-src="img" class="lazy" : / alt="The difference between custom path alias assets and static folders in vue-cli" > 或者p背景图形式: <p :style="{backgroundImage: 'url(' + img + ')'}"></p>After talking about pictures, I just want to mention the configuration related to a picture of vue-cli. The configuration in the picture below means: perform base64 conversion below the 10000b picture, so if there are some relatively small ones in the project The icon no longer needs to be processed by the image wizardwebpack+vue custom path aliasvue-cli uses webpack, you can also use the webpack custom alias function to customize the alias This function
When you are nested in multi-layer folders, you don’t have to find the path layer by layer. You can directly use the custom alias to find the location of the file.
Setting method: **Setting address: **webpack.base.conf.js file under the build folder
Specific settings:
resolve: { extensions: ['.js', '.vue', '.json'], alias: { 'vue$': 'vue/dist/vue.esm.js', '@': resolve('src'), 'static':path.resolve(__dirname, '../static'),//增加这一行代码 } },
How to use:
When using it, add a '~' in front of it like B in the screenshot below. Although webstorm here prompts an error, we You don't need to worry about it, the code will run normally.Interpretation:
Here, 'static' is given an address, so when the path is introduced in the program, '~static' can directly replace the path'.. /static', personal test, even if there are multiple levels of nesting, the path can be found successfully.npm remove module name to delete useless modules.
--save-dev and
--save
-- When save-dev installs dependencies, it will be placed under the devDependencies object in package.json. On the contrary, when you use
--save to install dependencies, it will appear under the dependencies object.
* –save-dev is something you rely on when developing, –save is something you still rely on after publishing. *
I have written two articles before about vue-cli configuration. Students who need it can take a look: Teach you how to use vue-cli scaffoldingReference jQuery, bootstrap and use sass and less to write css in vue-cli scaffoldingAfterwordThe above is the content of this article, which is some of my practice projects for a period of time Small accumulation, there will be some content in the follow-up, because the project is tight, I may meet you later.The above is the detailed content of The difference between custom path alias assets and static folders in vue-cli. For more information, please follow other related articles on the PHP Chinese website!

Python and JavaScript each have their own advantages, and the choice depends on project needs and personal preferences. 1. Python is easy to learn, with concise syntax, suitable for data science and back-end development, but has a slow execution speed. 2. JavaScript is everywhere in front-end development and has strong asynchronous programming capabilities. Node.js makes it suitable for full-stack development, but the syntax may be complex and error-prone.

JavaScriptisnotbuiltonCorC ;it'saninterpretedlanguagethatrunsonenginesoftenwritteninC .1)JavaScriptwasdesignedasalightweight,interpretedlanguageforwebbrowsers.2)EnginesevolvedfromsimpleinterpreterstoJITcompilers,typicallyinC ,improvingperformance.

JavaScript can be used for front-end and back-end development. The front-end enhances the user experience through DOM operations, and the back-end handles server tasks through Node.js. 1. Front-end example: Change the content of the web page text. 2. Backend example: Create a Node.js server.

Choosing Python or JavaScript should be based on career development, learning curve and ecosystem: 1) Career development: Python is suitable for data science and back-end development, while JavaScript is suitable for front-end and full-stack development. 2) Learning curve: Python syntax is concise and suitable for beginners; JavaScript syntax is flexible. 3) Ecosystem: Python has rich scientific computing libraries, and JavaScript has a powerful front-end framework.

The power of the JavaScript framework lies in simplifying development, improving user experience and application performance. When choosing a framework, consider: 1. Project size and complexity, 2. Team experience, 3. Ecosystem and community support.

Introduction I know you may find it strange, what exactly does JavaScript, C and browser have to do? They seem to be unrelated, but in fact, they play a very important role in modern web development. Today we will discuss the close connection between these three. Through this article, you will learn how JavaScript runs in the browser, the role of C in the browser engine, and how they work together to drive rendering and interaction of web pages. We all know the relationship between JavaScript and browser. JavaScript is the core language of front-end development. It runs directly in the browser, making web pages vivid and interesting. Have you ever wondered why JavaScr

Node.js excels at efficient I/O, largely thanks to streams. Streams process data incrementally, avoiding memory overload—ideal for large files, network tasks, and real-time applications. Combining streams with TypeScript's type safety creates a powe

The differences in performance and efficiency between Python and JavaScript are mainly reflected in: 1) As an interpreted language, Python runs slowly but has high development efficiency and is suitable for rapid prototype development; 2) JavaScript is limited to single thread in the browser, but multi-threading and asynchronous I/O can be used to improve performance in Node.js, and both have advantages in actual projects.


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

Video Face Swap
Swap faces in any video effortlessly with our completely free AI face swap tool!

Hot Article

Hot Tools

WebStorm Mac version
Useful JavaScript development tools

SublimeText3 English version
Recommended: Win version, supports code prompts!

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

PhpStorm Mac version
The latest (2018.2.1) professional PHP integrated development tool

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.
