Welcome to OGeek Q&A Community for programmer and developer-Open, Learning and Share
Welcome To Ask or Share your Answers For Others

Categories

0 votes
579 views
in Technique[技术] by (71.8m points)

vue 后端直接返回图片流,前端怎么直接显示在页面上

image.png
我网上搜了一下,说window.URL.createObjectURL(res)可以但是没有效果

fetchData() {
      const id = this.$route.query.companyId
      getCusInfo(id).then(res => {
        const _data = res.data
        this.detail = _data
        getFileDetail(_data.adAvatar).then(res => {
        //   const blob = new Blob([res.data], { type: 'image/png' })
        //   const url = window.URL.createObjectURL(blob)
        //   this.brandLogoUrl = url
        const src = window.URL.createObjectURL(res)
        this.brandLogoUrl = src
          console.log('res', res)
        })
        console.log('brandLogoUrl', this.brandLogoUrl)
      })
    },
<el-form-item label="广告头像" prop="adAvatar">
          <el-upload
            class="avatar-uploader"
            action="#"
            :http-request="advertiserUpload2"
            :show-file-list="false"
          >
            <img v-if="adAvatarUrl" :src="adAvatarUrl" class="avatar">
            <i v-else class="el-icon-plus avatar-uploader-icon" />
          </el-upload>
        </el-form-item>

我暂时是这么处理的
image.png


与恶龙缠斗过久,自身亦成为恶龙;凝视深渊过久,深渊将回以凝视…
Welcome To Ask or Share your Answers For Others

1 Reply

0 votes
by (71.8m points)

后端设置一下response type就行了,为什么前端要这么麻烦地去处理


与恶龙缠斗过久,自身亦成为恶龙;凝视深渊过久,深渊将回以凝视…
OGeek|极客中国-欢迎来到极客的世界,一个免费开放的程序员编程交流平台!开放,进步,分享!让技术改变生活,让极客改变未来! Welcome to OGeek Q&A Community for programmer and developer-Open, Learning and Share
Click Here to Ask a Question

...