Nuxt.js打包后报错DOMException: Failed to execute appendChild on

IT小君   2021-09-04T08:36:25

Nuxt.js打包后报错
DOMException: Failed to execute 'appendChild' on 'Node':
This node type does not support this method.

开发环境下报错
Mismatching childNodes vs. VNodes:

解决
1、template中可以限制只在客户端渲染

// version >= 2.9.0
<client-only></client-only>

// version < 2.9.0
<no-ssr></no-ssr>


2、script中可以使用客户端、服务端判断

if(process.client){
    console.log('client')
}

if(process.server){
    console.log('server')
}

点击广告,支持我们为你提供更好的服务
评论(28)