我是靠谱客的博主 健壮鸡,这篇文章主要介绍Vue将后端返回的图片展示在img标签中,现在分享给大家,希望可以做个参考。

java后台返回如图:
在这里插入图片描述
解决方法:

this.axios
  .get("接口地址", {
    responseType: "arraybuffer",  //重要
    params: 传给后端的数据
  })
  .then(response => {
    return (
      "data:image/png;base64," +
      btoa(
        new Uint8Array(response.data).reduce(
          (data, byte) => data + String.fromCharCode(byte),
          ""
        )
      )
    );
  })
  .then(data => {
    this.imgUrl = data; //赋值给img标签的src属性
  });

原文链接:https://blog.csdn.net/qq_37628661/article/details/104918677

最后

以上就是健壮鸡最近收集整理的关于Vue将后端返回的图片展示在img标签中的全部内容,更多相关Vue将后端返回内容请搜索靠谱客的其他文章。

本图文内容来源于网友提供,作为学习参考使用,或来自网络收集整理,版权属于原作者所有。
点赞(135)

评论列表共有 0 条评论

立即
投稿
返回
顶部