filter.js 988 B

1234567891011121314151617181920212223242526272829303132333435363738394041
  1. import Vue from 'vue'
  2. import { config } from '@/config/config'
  3. //保留两位小数
  4. Vue.filter('keepTwoNum',function(val){
  5. let value = Number(val)
  6. return value.toFixed(2)
  7. })
  8. //链接加时间戳
  9. Vue.filter("timestamp", function(link) {
  10. return link + '?t=' + new Date().getTime();
  11. });
  12. //截取第一张照片且判断是否有图片,没有图片按照传递类型随机输出
  13. Vue.filter("firstImg",function(arr,sizeType,imgType){
  14. let img;
  15. //图片类型判断
  16. if(arr){
  17. if(arr instanceof Array){
  18. img = arr[0]
  19. }else{
  20. img = arr.split(',')[0]
  21. }
  22. }else if(!arr){
  23. //如果没有图片则随机输出一张
  24. // if(imgType === 'farmer'){
  25. // const farmerList = ['carbon2/farmer/1.png','carbon2/farmer/2.png']
  26. // img = farmerList[Math.floor(Math.random() * farmerList.length)];
  27. // }
  28. img = '/static/img/inbuild.png'
  29. }
  30. // return config.imgUrl + img;
  31. return img;
  32. });
  33. Vue.filter("miniImg",function(img,quality){
  34. return img+'?imageMogr2/quality/'+quality
  35. });