Last active
May 31, 2018 02:29
-
-
Save troyz/b464bf2dd4b5dbbfee9a3ded4b91304a to your computer and use it in GitHub Desktop.
微信小程序<template>模板中图片路径处理
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
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