com-image.php 2.3 KB

12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849505152535455565758596061626364656667
  1. <template id="com-image">
  2. <div class="com-image" :style="style">
  3. <image v-if="src" :width="image_width" :height='image_height' :src="src" ></image>
  4. <image v-if="default_src" :width="image_width" :height='image_height' :src="default_src" ></image>
  5. <image v-if="!src&&!default_src" :width="image_width" :height='image_height' src="resources/img/mall/default_img.png" ></image>
  6. </div>
  7. </template>
  8. <script>
  9. Vue.component('com-image', {
  10. template: '#com-image',
  11. props: {
  12. src: String,
  13. default_src:String,
  14. mode: String,
  15. width: String,
  16. height: String,
  17. radius: String
  18. },
  19. data() {
  20. return {
  21. image_width: '50px',
  22. image_height: '50px',
  23. };
  24. },
  25. created() {
  26. },
  27. computed: {
  28. style() {
  29. let width = '50px';
  30. let height = '50px';
  31. let radius = '0%';
  32. let bgSize = 'cover';
  33. let bgPosition = 'center';
  34. switch (this.mode) {
  35. case 'scaleToFill':
  36. bgSize = '100% 100%';
  37. break;
  38. default:
  39. bgSize = 'cover';
  40. break;
  41. }
  42. if (this.width) {
  43. this.image_width = width = this.width + (isNaN(this.width) ? '' : 'px');
  44. }
  45. if (this.height) {
  46. this.image_height = height = this.height + (isNaN(this.height) ? '' : 'px');
  47. }
  48. if (this.radius) {
  49. radius = this.radius + (isNaN(this.radius) ? '' : '%');
  50. }
  51. let background_image_url = ``;
  52. // background_image_url = `background-image:url(${this.src ? this.src : 'resources/img/mall/default_img.png'});`;
  53. return background_image_url
  54. + `background-size:${bgSize};`
  55. + `background-position:${bgPosition};`
  56. + `width:${width};`
  57. + `height:${height};`
  58. + `border-radius: ${radius};`;
  59. },
  60. },
  61. methods: {},
  62. });
  63. </script>