Created
May 31, 2018 01:30
-
-
Save troyz/71873c32534a576fa59e2cdcfa3fdd03 to your computer and use it in GitHub Desktop.
微信小程序图片路径处理
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
// 本地项目图片上传到远程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