com-gallery.php 2.1 KB

12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849505152535455565758596061626364656667686970717273747576777879808182838485
  1. <style>
  2. .com-gallery .com-gallery-list {
  3. -webkit-flex-wrap: wrap;
  4. flex-wrap: wrap;
  5. }
  6. .com-gallery .com-gallery-item {
  7. width: 100px;
  8. height: 100px;
  9. border: 1px solid #e3e3e3;
  10. border-radius: 2px;
  11. margin-right: 10px;
  12. margin-bottom: 10px;
  13. position: relative;
  14. }
  15. .com-gallery .com-gallery-delete {
  16. position: absolute;
  17. right: -8px;
  18. top: -8px;
  19. padding: 4px 4px;
  20. }
  21. .com-gallery .com-gallery-img {
  22. max-width: 100%;
  23. max-height: 100%;
  24. }
  25. </style>
  26. <template id="com-gallery">
  27. <div class="com-gallery">
  28. <!--<el-button @click="test">test</el-button>-->
  29. <div class="com-gallery-list" flex>
  30. <template v-for="(item, index) in defaultList">
  31. <div class="com-gallery-item" flex="main:center cross:center" :style="reversedStyle">
  32. <el-button v-if="showDelete && item[urlKey ? urlKey : 'url']" class="com-gallery-delete"
  33. size="mini" type="danger" icon="el-icon-close" circle
  34. @click="deleted(item, index)"></el-button>
  35. <img class="com-gallery-img" :src="item[urlKey ? urlKey : 'url']">
  36. </div>
  37. </template>
  38. </div>
  39. </div>
  40. </template>
  41. <script>
  42. Vue.component('com-gallery', {
  43. template: '#com-gallery',
  44. props: {
  45. list: Array,
  46. urlKey: String,
  47. width: String,
  48. height: String,
  49. showDelete: Boolean,
  50. url: String
  51. },
  52. data() {
  53. return {};
  54. },
  55. created() {
  56. },
  57. computed: {
  58. reversedStyle() {
  59. return (this.height ? `height: ${this.height}; ` : '') + (this.width ? `width: ${this.width}; ` : '');
  60. },
  61. defaultList() {
  62. if (typeof this.url != 'undefined') {
  63. return [{
  64. url: this.url
  65. }];
  66. } else {
  67. return this.list;
  68. }
  69. }
  70. },
  71. methods: {
  72. test() {
  73. console.log(this);
  74. },
  75. deleted(item, index) {
  76. this.$emit('deleted', item, index);
  77. },
  78. },
  79. });
  80. </script>