前端图片上传

1.展示

在这里插入图片描述
在这里插入图片描述

{
title: ‘海报’,
key: ‘posterUrl’,
minWidth: 100,
align: ‘center’,
render: (h, params) => {
return h(‘img’, {
style: {
maxWidth: ‘100px’,
maxHeight: ‘100px’,
verticalAlign: ‘middle’
},
attrs: {
// src: this.$cmmApp.cmmResUrl(params.row.moviePicSrc)
src: params.row.posterUrl(后端传输地址)
},
on: {
‘click’: () => {
this.detail(params.row)
}
}
})
}
2.上传 展示
效果图
在这里插入图片描述

在这里插入图片描述

        <FormItem prop="moviePicSrc" label="海报">
          <Upload v-model="formInline.posterUrl" :before-upload="handleUpload" action="">
            <Button icon="ios-cloud-upload-outline">选择图片</Button>
          </Upload>
          <div v-if="formInline.fileName !== ''">
            &nbsp;&nbsp;{{ formInline.fileName }}
            <Button type="text" @click="upload('posterUrl')" :loading="loadingStatus">
              上传</Button>
          </div>
          <img alt="" id="myImg1" v-bind:src="formInline.posterUrl"
            style="margin-top:5%;display: block;width:45%" />
        </FormItem>

async upload(type) {
this.loadingStatus = true;
console.log("文件 = ", this.file.name);
let param = new FormData() // 创建form对象
param.append(‘file’, this.file) // 通过append向form对象添加数据
param.append(“type”, “1”); // 文件类型
let config = {
headers: { ‘Content-Type’: ‘multipart/form-data’ }
}
let res = await this. a x i o s . axios. axios.post(‘/device/image’, param, config);
console.log("res = ", JSON.stringify(res))
if (res && res.code === 200) {
console.log(‘已上传文件:path=’ + res.data);
if (type == ‘stillsUrl’) {
this.formInline.stillsUrl = res.msg;
} else {
this.formInline.posterUrl = res.msg;
}
}
this.loadingStatus = false;
},

/** 提交CSV后流处理方法 */
handleUpload(file) {
// 选择文件后触发验证关闭错误提示
// this.$refs[‘CSVfile’].validate(() => {})
let that = this
if (!/image/\w+/.test(file.type)) {
alert(‘请上传图片类型!’)
return
}
let reader = new FileReader()
// 读取文件
reader.readAsDataURL(file)
reader.onload = function (e) {
myImg.src = e.target.result
that.formInline.file = e.target.result
}
that.formInline.fileName = file.name
this.file = file;
return false
},

  • 0
    点赞
  • 0
    收藏
    觉得还不错? 一键收藏
  • 打赏
    打赏
  • 0
    评论

“相关推荐”对你有帮助么?

  • 非常没帮助
  • 没帮助
  • 一般
  • 有帮助
  • 非常有帮助
提交
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包

打赏作者

爱逛dn的小于

你的鼓励将是我创作的最大动力

¥1 ¥2 ¥4 ¥6 ¥10 ¥20
扫码支付:¥1
获取中
扫码支付

您的余额不足,请更换扫码支付或充值

打赏作者

实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值