Skip to content

Instantly share code, notes, and snippets.

@1c7
Created October 15, 2018 12:08
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 1c7/ae10161607e56f9fbd0d51dd6b3bf748 to your computer and use it in GitHub Desktop.
Save 1c7/ae10161607e56f9fbd0d51dd6b3bf748 to your computer and use it in GitHub Desktop.
微信小程序 wxs 头像 filter
/*
用户的头像 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
}
}
@1c7
Copy link
Author

1c7 commented Oct 15, 2018

以上代码公开出来,是为了给其他小程序开发者参考。
因为不能用 startsWith, 就只能用 indexOf 了

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment