打包的时候回报Error: v-html will override element children.的错误
使用v-html指令,在打包的时候会出现这样的错误 Error: v-html will override element children.
``vite v1.0.0-rc.4 / Building for production... [vite] Build errored out. Error: v-html will override element children.
Hey! This must be an error from Vue! It happens in a case when you do something like:
<div v-html="'<p>test</p>'">text</div>
That means the text will be overridden by <p>test</p>
Remove the content inside Element and the error should disappear!
As @sionzeecz said.
Hey! This must be an error from Vue! It happens in a case when you do something like:
<div v-html="'<p>test</p>'">text</div>That means the
textwill be overridden by<p>test</p>Remove the content inside Element and the error should disappear!
thank you
I have an edge case where I need to have that something like that, I remember Vue2 used to work, there is a way to make it work?
a config, a hook, or something similar?
Thanks
That doesn't make sense. What should be the proper output if both options are there? What do you expect on output?
Yeah sorry I did not explain myself properly, If I have
<div v-html="'<p>foo</p>'">bar</div>
I expect the ouput
<div><p>foo</p></div>
Just like Vue 3 at development mode does
The "bar" is not having sense to be there. That is what Vue 3 complains about. The error/warning is there because it thinks you are doing a mistake. It is telling you that the whole body of the node will be replaced with the context of v-html variable.
If you're upgrading Vue2 project to Vue3 then the proper way is to remove the body and keep the v-html only.
I don't see a real reason why it should be configurable. If you keep it there then it can also confuse next people who are working on the same project or the new comers.
Real reason for this, at least for me and it seems quite obvious, is to have a default value.