For AI agents: the complete documentation index is available at https://heyq02.com/llms.txt, the full documentation bundle is available at https://heyq02.com/llms-full.txt, and this page is available as Markdown at https://heyq02.com/blog/posts/react-path-alias-background-image.md.
跳到主要内容

React 中使用路径别名引用资源设置背景图

预计阅读时间: 小于 1 分钟

为了解决 url() 路径引入问题,将其转化成 base64 编码进而拼接字符串。

1. 问题背景

使用 css-in-js 为元素添加背景图时,会产生奇怪的 bug。

可以看到,路径前后多出了奇怪的引号。

先路径别名引入资源,再拼接字符串。但是这样是使用了编码的方式。

一种取巧的方式。