Skip to content

Instantly share code, notes, and snippets.

@troyz
Last active May 31, 2018 02:29
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/b464bf2dd4b5dbbfee9a3ded4b91304a to your computer and use it in GitHub Desktop.
Save troyz/b464bf2dd4b5dbbfee9a3ded4b91304a to your computer and use it in GitHub Desktop.
微信小程序<template>模板中图片路径处理
var o = {
get: function(localImagePath)
{
// 本地项目图片上传到远程CDN图片服务器的路径
var imageCDNPrefix = 'http://******.clouddn.com/mp-travel/';
// 使用项目中的图片 or 使用远程CDN服务器 的图片。
var useLocalImage = false;
if(useLocalImage)
{
return localImagePath;
}
var imagePrefix = 'assets/images';
var index = localImagePath.indexOf(imagePrefix);
if(index === -1)
{
return localImagePath;
}
var endWithSlash = (imageCDNPrefix[imageCDNPrefix.length - 1] === '/');
var imagePath = imageCDNPrefix + (endWithSlash ? '' : '/') + localImagePath.substring(index);
return imagePath;
}
}
module.exports = {
get: o.get
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment