vite静态资源处理
/**
* 获取完整解析静态资源的url,如图片、svg等
* @param {string} path 静态资源在在assets中的地址,例如:images/pubilc/logo.png
* @returns {string}
*/
export function getStaticUrl(path: string | undefined): string {
if (typeof path == "undefined") return "";
let paths = path.split("/");
// 去掉空值或者.或者..
paths = paths.filter((item) => item !== "" && item !== "." && item !== "..");
return new URL(`../assets/${paths.join("/")}`, import.meta.url).href;
}
本文来自博客园,作者:小周同学~,转载请注明原文链接:https://www.cnblogs.com/xiaozhou-wuyu/p/19108255

浙公网安备 33010602011771号