Vuejs error: Client-rendered virtual DOM tree does not match server-rendered
P粉006847750
2023-08-27 20:39:55
<p>I'm using Nuxt.js/Vuejs in my app and I keep getting this error in different places: </p>
<pre class="brush:php;toolbar:false;">The client-side rendered virtual DOM tree is not matching server-rendered content.
This is likely caused by incorrect HTML markup, for example nesting block-level elements inside <p>, or missing <tbody>.
Bailing hydration and performing full client-side render.</pre>
<p>I would like to know what is the best way to debug this error? Is this a way I can log/get the virtual DOM trees of client and server so I can compare and find where the error is? </p>
<p>My application is large and manual verification is difficult. </p>
For me, this error happened because while getting the array list in
AsyncData
and rendering thetag viav-for, I put >v-for
code in
block and resolve issuePartial answer: Using Chrome DevTools, you can locate the problem and see exactly which element is causing it. Do the following (I'm doing this using Nuxt 5.6.0 and Chrome 64.0.3282.186)
msg
variable.Hydro
function call 4 lines above the execution line inpatch
. A hyperlink to the source ofHydrate
will open.enchanted
function, move about 15 lines from the beginning and set a breakpoint that returnsfalse
false# after
assertNodeMatchreturns ##. Set a breakpoint there and delete all other breakpoints.
function. Switch to the DevTools console and evaluate
elm, then
vnode. Here elm appears to be a server-rendered DOM element, and vnode is a virtual DOM node. Elm prints to HTML so you can figure out where the error occurs.