Created
October 15, 2018 12:08
-
-
Save 1c7/ae10161607e56f9fbd0d51dd6b3bf748 to your computer and use it in GitHub Desktop.
微信小程序 wxs 头像 filter
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
/* | |
用户的头像 url 有3种可能: | |
1. 空 | |
代表是默认头像 | |
2. avatar-2018-07-24-16-26-52-Fs0NsdbSY8dPPvJjiXFKs-M8ISLG.jpg | |
代表是用户自定义头像,前面要加上 https://img.wittcism.com | |
3. https://wx.qlogo.cn/mmopen/vi_32/Da3any5kia1kePickTDzlMJTRQMFJbaebPebFlicbXF6WkT6vH325DDGcNm3zNZX1r4Wtpg7ZjUarezKPVvV8bHpw/132" | |
代表是微信登录的头像 | |
avatar 这个 filter 要进行正确的处理,3种情况下都返回正确的 URL | |
*/ | |
var avatar = function(value){ | |
console.log(value); | |
if(value == ''){ | |
return "https://wittcism.com/static/img/default_avatar.svg" | |
}else if(value.indexOf("https://")!== -1){ | |
return value | |
}else{ | |
return "https://img.wittcism.com" + value | |
} | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
以上代码公开出来,是为了给其他小程序开发者参考。
因为不能用 startsWith, 就只能用 indexOf 了