把你吃成个大胖子 2021-08-27 11:02 采纳率: 58.7%
浏览 238
已结题

子组件内渲染问题,第一次进来无法渲染成功,第二次才行

父组件


  <!-- 流程图弹窗 -->
   <el-dialog
    title="流程图"
    :visible.sync="flowChartShow"
    width="70%"
    :before-close="flowChartClose"
    >
     <!-- 流程图   子组件-->
     <auth-embed
      :authSrc="`${imageProcess}?baseId=${query.id}`"
      style="width: 100%; height: 350px"
     />
   </el-dialog>

子组件

<template>
  <div>
    <embed ref="embed" style="width: 100%; height: 100%; display: block" />
  </div>
</template>
<script>
import { getToken } from '@/utils/auth'
export default {
  name: "AuthEmbed",
  props: {
    authSrc: {
      type: String,
      required: false,
      default: "",
    }
  },
  mounted() {
    let token = 'bearer ' + getToken()
    Object.defineProperty(Image.prototype, 'authsrc', {
      writable: true,
      enumerable: true,
      configurable: true
    })
    let embed = this.$refs.embed
    let request = new XMLHttpRequest();
    request.responseType = 'blob';
    console.log(this.authSrc);
    request.open('get', this.authSrc, true);
    request.setRequestHeader('Authorization', token);

    request.onreadystatechange = e => {
      if (request.readyState == XMLHttpRequest.DONE && request.status == 200) {
        embed.src = URL.createObjectURL(request.response);
        embed.onload = () => {
          URL.revokeObjectURL(embed.src);
        }
      }
    };

    request.send(null);
  },
}
</script>

第一次进来的时候

img
这两个值都是undefined 第二次就没事 this.authSrc第一次进来是有值的

这应该怎么调试

img

  • 写回答

6条回答 默认 最新

  • 把你吃成个大胖子 2021-09-01 16:47
    关注

    已经搞定了
    只需要把

    :visible.sync="flowChartShow"
    

    修改为

     v-if="flowChartB"
    :visible.sync="flowChartB"
    

    然后在计算属性里面写

     computed: {
        flowChartB() {
          return (this.imageProcess && this.flowChartShow) ? true : false
        },
    }
    

    最后在子组件里面加个src就行

    <embed ref="embed" src='' style="width: 100%; height: 100%; display: block" />
    
    本回答被题主选为最佳回答 , 对您是否有帮助呢?
    评论
查看更多回答(5条)

报告相同问题?

问题事件

  • 系统已结题 9月9日
  • 已采纳回答 9月1日
  • 创建了问题 8月27日

悬赏问题

  • ¥15 #MATLAB仿真#车辆换道路径规划
  • ¥15 java 操作 elasticsearch 8.1 实现 索引的重建
  • ¥15 数据可视化Python
  • ¥15 要给毕业设计添加扫码登录的功能!!有偿
  • ¥15 kafka 分区副本增加会导致消息丢失或者不可用吗?
  • ¥15 微信公众号自制会员卡没有收款渠道啊
  • ¥100 Jenkins自动化部署—悬赏100元
  • ¥15 关于#python#的问题:求帮写python代码
  • ¥20 MATLAB画图图形出现上下震荡的线条
  • ¥15 关于#windows#的问题:怎么用WIN 11系统的电脑 克隆WIN NT3.51-4.0系统的硬盘