1
0

myimg.vue 1.1 KB

1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950515253545556575859606162636465666768697071727374
  1. <template>
  2. <div class="divimg">
  3. <img :src="path" :width="nwidth" :style="style">
  4. </div>
  5. </template>
  6. <style scoped>
  7. .divimg {
  8. text-align : center ;
  9. }
  10. img {
  11. border : 1px solid purple ;
  12. object-fit: contain ;
  13. }
  14. </style>
  15. <script>
  16. export default {
  17. computed : {
  18. path : function() {
  19. return "/" + this.me + "/images/" + this.data ;
  20. } ,
  21. nwidth : function() {
  22. return this.width || '80%' ;
  23. }
  24. } ,
  25. props : {
  26. me : String ,
  27. data : String ,
  28. dim : String ,
  29. width : String ,
  30. } ,
  31. data() {
  32. return {
  33. style : {}
  34. }
  35. } ,
  36. mounted : function() {
  37. if ( this.dim ) {
  38. this.style = {} ;
  39. const regex = /(\d+)x(\d+)/;
  40. const found = this.dim.match(regex);
  41. if ( found[1] > 0 ) {
  42. this.style['width'] = found[1] + "px" ;
  43. }
  44. if ( found[2] > 0 ) {
  45. this.style['height'] = found[2] + "px" ;
  46. }
  47. console.log ( { style : this.style } ) ;
  48. }
  49. } ,
  50. methods : {
  51. }
  52. }
  53. </script>