From c41f452d5f12dbe3860ff8e16edad6e69c7a0326 Mon Sep 17 00:00:00 2001 From: chendishen <690630770@qq.com> Date: Mon, 21 Sep 2020 22:22:44 +0800 Subject: [PATCH 1/2] =?UTF-8?q?=E4=BF=AE=E6=94=B9SSR=E5=BC=95=E5=85=A5?= =?UTF-8?q?=E6=96=B9=E5=BC=8F?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit SSR使用看板娘时,使用自定义Document引入基础依赖 --- README.md | 51 +++++++++++++++++++++++++-------------------------- 1 file changed, 25 insertions(+), 26 deletions(-) diff --git a/README.md b/README.md index fba01d3..b100aa5 100644 --- a/README.md +++ b/README.md @@ -84,39 +84,38 @@ const App = () => ( ## 🔨 Usage for SSR ##### 如:create-next-app -项目根目录创建components文件夹,并在其中创建Header.js +创建文件`./pages/_document.js` ```jsx -import React from 'react' -import Head from 'next/head' +import Document, { Html, Head, Main, NextScript } from 'next/document' -const Header = () => ( -
- - - - - -
-) +class MyDocument extends Document { + static async getInitialProps(ctx) { + const initialProps = await Document.getInitialProps(ctx) + return { ...initialProps } + } -export default Header + render() { + return ( + + {/* */} + + + + +
+ + + + ) + } +} + +export default MyDocument ``` ```jsx import dynamic from 'next/dynamic' - -const DynamicComponentWithNoSSR = dynamic(import('../components/Header'), { - ssr: false -}) - const ReactLive2d = dynamic(import('react-live2d'), { ssr: false }) @@ -180,4 +179,4 @@ api 文档 (待完善,如有需要功能欢迎提[issue](https://github.com/ 当menuList 传入非空数组时,其中的字段: | 成员 | 说明 | 类型 | 默认值 | | :-----: | ----- | ----- | ----- | -| Mtab | 切换看板娘 | String | 'Mtab' | \ No newline at end of file +| Mtab | 切换看板娘 | String | 'Mtab' | From d58f3c64b9e4f7948550dd81583cf2aefecbd237 Mon Sep 17 00:00:00 2001 From: chendishen <690630770@qq.com> Date: Tue, 22 Sep 2020 09:02:44 +0800 Subject: [PATCH 2/2] Update README.md --- README.md | 1 - 1 file changed, 1 deletion(-) diff --git a/README.md b/README.md index b100aa5..07f9ed6 100644 --- a/README.md +++ b/README.md @@ -122,7 +122,6 @@ const ReactLive2d = dynamic(import('react-live2d'), { export default function Home() ( <> -