-
-
Notifications
You must be signed in to change notification settings - Fork 8.2k
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
v-html 在 SSR 与 CSR 时的表现不一致 #10725
Comments
Sign up for free
to subscribe to this conversation on GitHub.
Already have an account?
Sign in.
Vue version
3.4.23
Link to minimal reproduction
https://stackblitz.com/~/github.com/KazariEX/vue-inconsistent-v-html
Steps to reproduce
undefined
和null
undefined
和null
消失What is expected?
首次进入主页时(SSR),没有
undefined
和null
What is actually happening?
首次进入主页时(SSR),
v-html
将undefined
和null
作为字符串渲染在了innerHTML
中System Info
Any additional comments?
v-html
的值在 SSR 时会将原始值直接放入插值语法中,这会触发 String 类型的隐式转换;而对 DOM 元素设置innerHTML
时,null
值会被处理为空字符串,两者表现并不一致;在 CSR 时,undefined
值会被处理为空字符串,而innerHTML
的原生效果是转换为字符串后输出——文档中的 “更新元素的 innerHTML” 并不准确。同理,
v-text
在渲染null
值时也有同样的问题,Vue 的文本插值语法与textContent
并不等价。The text was updated successfully, but these errors were encountered: