Skip to content

Instantly share code, notes, and snippets.

@troyz
Created May 31, 2018 01:30
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save troyz/71873c32534a576fa59e2cdcfa3fdd03 to your computer and use it in GitHub Desktop.
Save troyz/71873c32534a576fa59e2cdcfa3fdd03 to your computer and use it in GitHub Desktop.
微信小程序图片路径处理
// 本地项目图片上传到远程CDN图片服务器的路径
const imageCDNPrefix = 'http://******.clouddn.com/mp-travel/';
// 使用项目中的图片 or 使用远程CDN服务器 的图片。
const useLocalImage = false;
export default class MPImageUtil
{
// 获取图片路径
static getImagePath(localImagePath)
{
if(useLocalImage)
{
return localImagePath;
}
let imagePrefix = 'assets/images';
let index = localImagePath.indexOf(imagePrefix);
if(index === -1)
{
return localImagePath;
}
let imagePath = imageCDNPrefix + (imageCDNPrefix.endsWith('/') ? '' : '/') + localImagePath.substr(index);
return imagePath;
}
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment