cloud-image.vue 1.1 KB

12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849505152535455565758596061626364656667686970
  1. <template>
  2. <view @click="onClick" :style="{width,height}">
  3. <image v-if="cSrc" :style="{width,height}" :src="cSrc" :mode="mode"></image>
  4. </view>
  5. </template>
  6. <script>
  7. export default {
  8. name: "cloud-image",
  9. emits:['click','switchChange'],
  10. props: {
  11. mode: {
  12. type:String,
  13. default () {
  14. return 'widthFix'
  15. }
  16. },
  17. src: {
  18. // type:String,
  19. default () {
  20. return ""
  21. }
  22. },
  23. width: {
  24. type:String,
  25. default () {
  26. return '100rpx'
  27. }
  28. },
  29. height: {
  30. type:String,
  31. default () {
  32. return '100rpx'
  33. }
  34. }
  35. },
  36. watch: {
  37. src:{
  38. handler(src) {
  39. // console.log(src);
  40. // console.log(src.substring(0, 8));
  41. if (src&&src.substring(0, 8) == "cloud://") {
  42. uniCloud.getTempFileURL({
  43. fileList: [src]
  44. }).then(res=>{
  45. // console.log(res);
  46. this.cSrc = res.fileList[0].tempFileURL
  47. })
  48. }else{
  49. this.cSrc = src
  50. }
  51. },
  52. immediate: true
  53. }
  54. },
  55. async mounted() {
  56. },
  57. methods:{
  58. onClick(){
  59. this.$emit('click')
  60. }
  61. },
  62. data() {
  63. return {
  64. cSrc:false
  65. };
  66. }
  67. }
  68. </script>