当前位置:网站首页>Vite dynamically loads static resource pictures, and fixes the 404 problem of pictures after packaging.
Vite dynamically loads static resource pictures, and fixes the 404 problem of pictures after packaging.
2022-07-25 02:24:00 【TangAcrab】
1、 solve . Use new URL
/*** * @description vite Dynamically load static resource pictures * @params string name - Image name */
export const dynamicGetImg = (name: string) => {
try {
return new URL(`../assets/menu-icon/${
name}`, import.meta.url).href
} catch (error) {
console.log(error)
}
}
Just pass in the name of the picture in the directory
Reference article Acknowledgement
边栏推荐
- [leetcode] 3. Longest substring without repeated characters - go language problem solution
- Details of C language compilation preprocessing and comparison of macros and functions
- Scalar, vector, matrix calculus
- Origin and development of philosophy Hegel external historical form
- Digital power supply -- Chapter 1
- Deep understanding of string class
- What are the basic skills of engineers? How to practice? -- Learning experience sharing "suggestions collection"
- How to communicate with aliens
- Actf questions (dropper+master_of_dns)
- After upgrading v2.1.0, the synchronization failed
猜你喜欢

Digital power supply -- Chapter 1

How to use ES6 async and await (basic)

An article explains unsupervised learning in images in detail

"I gave up programming and wrote a 1.3 million word hard science fiction."

Focus on improving women's and children's sense of gain, happiness and security! In the next ten years, Guangzhou Women's and children's undertakings will make such efforts

Use SAP ui5 application to consume create and delete operations of OData in business application studio

Chinese son-in-law OTA Ono became the first Asian president of the University of Michigan, with an annual salary of more than 6.5 million!

July 8, 2022

Pycharm writes SQLite statements without code prompts
It's still a synchronization problem
随机推荐
Can PostgreSQL CDC only connect to the main database? Connection from the library reports an error logical decoden
Remove & lt; li> Front blank distance
After six years of precipitation, new consumption has found a digital transformation paradigm
HAC cluster is modified to stand-alone
UDP message structure and precautions
Master jedispoolconfig parameter configuration and learn tuning skills
Coal industry supply chain centralized mining system: digitalization to promote the transformation and upgrading of coal industry
Open sharing of scientific data in the context of open science: the practice of the national Qinghai Tibet Plateau scientific data center
Computing network, AI first, shengteng AI helps operators' Digital Transformation -- work together to win-win Computing Era
Digital power supply -- Chapter 1
Query the thread information of MySQL server (detailed explanation)
Peripherals: timer, watchdog and RTC
When sharing a folder, the 'attempt to share xxxxx
How MySQL 8.0 based on TRX_ Id find the statement of the whole transaction
Detailed explanation of manually writing servlet in idea
Simulation Implementation of [STL] string class
PostgreSQL views tables, table indexes, views, table structures, and parameter settings
Android memory optimized disk cache
Agreement on sharing agricultural scientific data in China
Gbase 8s how to query relational databases in sentences to select sample syntax and results of data from complex types