netImage.vue 1.5 KB

12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849505152535455565758596061626364656667686970717273
  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.awayqtw.com/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 http= url.substring(0,8);
  52. if(http==='https://'){
  53. return url;
  54. }
  55. else if(http==='/static/'){
  56. return url;
  57. }
  58. else{
  59. // console.log(this.baseUrl+url);
  60. return (this.baseUrl+url);
  61. }
  62. }
  63. },
  64. }
  65. </script>
  66. <style>
  67. .imageBGV{
  68. background-color:floralwhite;
  69. border: 1rpx solid lightgray;
  70. }
  71. </style>