Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

子应用中在动态修改图片的地址导致图片频繁切换 #1202

Open
SepVeneto opened this issue May 9, 2024 · 0 comments
Open
Labels

Comments

@SepVeneto
Copy link
Contributor

问题描述

通过new ImageappendChild添加图片,当图片地址会动态修改时会出现dom上频繁添加删除的现象。但是当子应用独立运行的时候就没有这个问题

<template>
  <div ref="imgRef"></div>
</template>

<script setup lang="ts">
import { onMounted, ref, shallowRef, watch } from 'vue'

const imgRef = ref()

const props = defineProps({
  src: {
    type: String,
    required: true,
  },
})

onMounted(() => {
  loadImage()
})
watch(() => props.src, () => {
  loadImage()
})
const _img = shallowRef()
function loadImage() {
  const img = new Image()

  img.onload = () => {
    if (_img.value) {
      _img.value.remove()
    }
    _img.value = img
    imgRef.value.appendChild(img)
  }
  img.src = props.src
}
</script>

复现步骤

克隆复现仓库

pnpm i
cd packages/base
pnpm dev

cd packages/micro
pnpm dev

访问http://localhost:8987

观察到最下方的图标会频繁在vue.svgvite.svg中切换

直接访问子应用http://localhost:8988

观察到最下方的图标初始为vite.svg,0.3s后切换为vue.svg

上传截图

复现仓库

microapp-demo

环境信息

  • micro-app版本:1.0.0-rc.5
  • 主应用前端框架&版本:vue&3.4.27
  • 子应用前端框架&版本:vue&3.4.27
  • 构建工具&版本:vite&5.2.11
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
Projects
None yet
Development

No branches or pull requests

2 participants