netImage.vue 1.6 KB

1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950515253545556575859606162636465666768697071727374757677
  1. <template>
  2. <view :class="backgrS==1?'':'imageBGV'" :style="{width:width+'rpx',height:height+'rpx',borderRadius:bradius+'rpx'}">
  3. <image :style="{width:width+'rpx',height:height+'rpx',borderRadius:bradius+'rpx'}" :src="compleurl(comUrl)" :mode="mymode" @error="imageError" @click="myimageclick"></image>
  4. </view>
  5. </template>
  6. <script>
  7. export default {
  8. name:"netImage",
  9. props:{
  10. mysrc: '',
  11. mymode:'',
  12. width:0,
  13. height:0,
  14. bradius:0,
  15. backgrS:0,
  16. },
  17. data() {
  18. return {
  19. defaultImage:'/static/logo.png',
  20. baseUrl:'https://backend.cityexpress168.com.vn/prod-api',
  21. showdefault:0,
  22. comUrl:this.mysrc
  23. };
  24. },
  25. watch: {
  26. mysrc(val){
  27. this.showdefault=0;
  28. this.comUrl = this.mysrc
  29. //console.log('watch-------------')
  30. //console.log(this.comUrl);
  31. }
  32. },
  33. methods:{
  34. imageError(){
  35. this.comUrl ='';// this.defaultImage;//morentup
  36. //console.log('imageError---------------')
  37. //console.log(this.baseUrl+this.comUrl)
  38. this.showdefault=1;
  39. },
  40. myimageclick(){
  41. this.$emit('Emyimageclick',this.comUrl);
  42. },
  43. compleurl(url){
  44. //console.log('------compleurl',url)
  45. if(!url){
  46. return '';
  47. }
  48. if(url.length<8){
  49. return '';
  50. }
  51. var https= url.substring(0,8);
  52. if(https==='https://'){
  53. return url;
  54. }
  55. var http= url.substring(0,7);
  56. if(http==='http://'){
  57. return url;
  58. }
  59. else if(http==='/static/'){
  60. return url;
  61. }
  62. else{
  63. //console.log(this.baseUrl+url);
  64. return (this.baseUrl+url);
  65. }
  66. }
  67. },
  68. }
  69. </script>
  70. <style>
  71. .imageBGV{
  72. background-color:floralwhite;
  73. border: 1rpx solid lightgray;
  74. }
  75. </style>