上传图片组件 UploadImg.vue
复制 | |
| <template> |
| <!-- 上传附件--> |
| <view class="comment-image-style"> |
| <view class="img" v-if="imgArr.length === 0 "> |
| <u-image width="100%" height="100%" src="/static/icon/upload.png" |
| alt="upload" |
| @click="uploadImg"></u-image> |
| </view> |
| |
| <view class="imgBox-style"> |
| <view class="flex-item-style" v-for="(item,index) in imgArr" :key="index" |
| > |
| <view v-if="show" style="width:0;height:0;"> |
| <u-icon class="icon-style" name="close-circle" color="#EF0000" size="28" |
| @click="deleteImg(index)" |
| ></u-icon> |
| </view> |
| <view> |
| <u-image class="u-m-20" width="150rpx" height="150rpx" :src="item" |
| @click="previewImage(index)"> |
| </u-image> |
| </view> |
| </view> |
| <view class="img" v-if="(imgArr.length > 0 && imgArr.length < 9 && show)"> |
| <u-image width="100%" height="100%" src="/static/icon/upload.png" |
| alt="addImg" |
| @click="addImg"> |
| </u-image> |
| </view> |
| </view> |
| </view> |
| </template> |
| |
| <script> |
| export default { |
| name: '', |
| props: { |
| imgArr: { |
| type: Array |
| }, |
| show: { |
| type: Boolean |
| } |
| }, |
| data() { |
| return {}; |
| }, |
| computed: {}, |
| watch: {}, |
| methods: { |
| uploadImg() { |
| this.$emit('uploadImg'); |
| }, |
| addImg() { |
| this.$emit('addImg'); |
| }, |
| deleteImg(index) { |
| this.$emit('deleteImg', index); |
| }, |
| previewImage(index) { |
| this.$emit('previewImage', index); |
| } |
| } |
| }; |
| </script> |
| |
| <style lang="scss" scoped> |
| |
| .comment-image-style { |
| height: 100%; |
| width: 100%; |
| } |
| |
| .img { |
| margin: 20rpx; |
| width: 150rpx; |
| height: 150rpx |
| } |
| |
| .imgBox-style { |
| display: flex; |
| flex-direction: row; |
| flex-wrap: wrap; |
| justify-content: start; |
| text-align: center; |
| width: 100%; |
| |
| .flex-item-style { |
| width: 25%; |
| } |
| |
| .icon-style { |
| position: relative; |
| right: -140rpx; |
| top: 16rpx; |
| z-index: 999; |
| } |
| } |
| </style> |
方法
复制 | |
| uploadImg() { |
| uni.chooseImage({ |
| count: 9, |
| sizeType: ['original', 'compressed'], |
| sourceType: ['album'], |
| success: (res) => { |
| this.imgArr = res.tempFilePaths; |
| }, |
| fail: (res) => { |
| console.log(res); |
| } |
| }); |
| }, |
| |
| addImg() { |
| uni.chooseImage({ |
| count: 9 - this.imgArr.length, |
| sizeType: ['original', 'compressed'], |
| sourceType: ['album'], |
| success: (res) => { |
| this.imgArr = this.imgArr.concat(res.tempFilePaths); |
| }, |
| fail: (res) => { |
| console.log(res); |
| } |
| }); |
| }, |
| |
| deleteImg(index) { |
| uni.showModal({ |
| title: '提示', |
| content: '是否要删除此图片?', |
| success: (res) => { |
| if (res.confirm) { |
| this.imgArr.splice(index, 1); |
| } |
| } |
| }); |
| }, |
| |
| previewImage(index) { |
| uni.previewImage({ |
| current: index, |
| urls: this.imgArr |
| }); |
| } |
【推荐】国内首个AI IDE,深度理解中文开发场景,立即下载体验Trae
【推荐】编程新体验,更懂你的AI,立即体验豆包MarsCode编程助手
【推荐】抖音旗下AI助手豆包,你的智能百科全书,全免费不限次数
【推荐】轻量又高性能的 SSH 工具 IShell:AI 加持,快人一步
· 无需6万激活码!GitHub神秘组织3小时极速复刻Manus,手把手教你使用OpenManus搭建本
· Manus爆火,是硬核还是营销?
· 终于写完轮子一部分:tcp代理 了,记录一下
· 别再用vector<bool>了!Google高级工程师:这可能是STL最大的设计失误
· 单元测试从入门到精通