vite icon indicating copy to clipboard operation
vite copied to clipboard

打包的时候回报Error: v-html will override element children.的错误

Open seasonl2014 opened this issue 6 years ago • 9 comments

使用v-html指令,在打包的时候会出现这样的错误 Error: v-html will override element children.

seasonl2014 avatar Aug 13 '20 12:08 seasonl2014

``vite v1.0.0-rc.4 / Building for production... [vite] Build errored out. Error: v-html will override element children.

seasonl2014 avatar Aug 13 '20 12:08 seasonl2014

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!

sionzee avatar Aug 13 '20 19:08 sionzee

As @sionzeecz said.

underfin avatar Aug 14 '20 12:08 underfin

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!

thank you

seasonl2014 avatar Aug 15 '20 12:08 seasonl2014

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

Rogant avatar Oct 13 '20 23:10 Rogant

That doesn't make sense. What should be the proper output if both options are there? What do you expect on output?

sionzee avatar Oct 13 '20 23:10 sionzee

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

Rogant avatar Oct 13 '20 23:10 Rogant

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.

sionzee avatar Oct 13 '20 23:10 sionzee

Real reason for this, at least for me and it seems quite obvious, is to have a default value.

atorscho avatar Oct 21 '20 18:10 atorscho