cloud-image.vue 1.5 KB

12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849505152535455565758596061626364656667686970717273
  1. <template>
  2. <view @click="onClick" :style="{width,height}" style="justify-content: center;">
  3. <image v-if="cSrc" :style="{width,height}" :src="cSrc" :mode="mode"></image>
  4. </view>
  5. </template>
  6. <script>
  7. /**
  8. * cloud-image
  9. * @description 兼容普通资源和unicloud图片资源渲染的组件
  10. * @property {String} mode 图片裁剪、缩放的模式。默认为widthFix,支持所有image组件的mode值
  11. * @property {String} src 资源完了链接或uniCloud云存储资源的fileid
  12. * @property {String} width 图片的宽,默认为:100rpx
  13. * @property {String} height 图片的高,默认为:100rpx
  14. * @event {Function} click 点击 cloud-image 触发事件
  15. */
  16. export default {
  17. name: "cloud-image",
  18. emits:['click'],
  19. props: {
  20. mode: {
  21. type:String,
  22. default () {
  23. return 'widthFix'
  24. }
  25. },
  26. src: {
  27. // type:String,
  28. default () {
  29. return ""
  30. }
  31. },
  32. width: {
  33. type:String,
  34. default () {
  35. return '100rpx'
  36. }
  37. },
  38. height: {
  39. type:String,
  40. default () {
  41. return '100rpx'
  42. }
  43. }
  44. },
  45. watch: {
  46. src:{
  47. handler(src) {
  48. if (src&&src.substring(0, 8) == "cloud://") {
  49. uniCloud.getTempFileURL({
  50. fileList: [src]
  51. }).then(res=>{
  52. this.cSrc = res.fileList[0].tempFileURL
  53. })
  54. }else{
  55. this.cSrc = src
  56. }
  57. },
  58. immediate: true
  59. }
  60. },
  61. methods:{
  62. onClick(){
  63. this.$emit('click')
  64. }
  65. },
  66. data() {
  67. return {
  68. cSrc:false
  69. };
  70. }
  71. }
  72. </script>