fix(chat): avoid link card render loop

This commit is contained in:
2977094657
2026-03-16 16:08:26 +08:00
Unverified
parent 7c5a18a3b5
commit ebce129315
+10 -8
View File
@@ -1,5 +1,5 @@
<script>
import { defineComponent, h, ref } from 'vue'
import { defineComponent, h, ref, watch } from 'vue'
import miniProgramIconUrl from '~/assets/images/wechat/mini-program.svg'
export default defineComponent({
@@ -19,7 +19,15 @@ export default defineComponent({
setup(props) {
const fromAvatarImgOk = ref(false)
const fromAvatarImgError = ref(false)
const lastFromAvatarUrl = ref('')
watch(
() => String(props.fromAvatar || '').trim(),
() => {
fromAvatarImgOk.value = false
fromAvatarImgError.value = false
},
{ immediate: true }
)
const getFromText = () => {
const raw = String(props.from || '').trim()
@@ -47,12 +55,6 @@ export default defineComponent({
const isCoverVariant = !isMiniProgram && String(props.variant || '').trim() === 'cover'
const Tag = canNavigate ? 'a' : 'div'
if (fromAvatarUrl !== lastFromAvatarUrl.value) {
lastFromAvatarUrl.value = fromAvatarUrl
fromAvatarImgOk.value = false
fromAvatarImgError.value = false
}
const showFromAvatarImg = Boolean(fromAvatarUrl) && !fromAvatarImgError.value
const showFromAvatarText = (!fromAvatarUrl) || (!fromAvatarImgOk.value)
const fromAvatarStyle = fromAvatarImgOk.value