mirror of
https://github.com/chendishen/react-live2d.git
synced 2024-11-22 11:49:59 +08:00
This commit is contained in:
commit
65e2fdeb46
48
README.md
48
README.md
@ -84,46 +84,44 @@ const App = () => (
|
|||||||
## 🔨 Usage for SSR
|
## 🔨 Usage for SSR
|
||||||
##### 如:create-next-app
|
##### 如:create-next-app
|
||||||
|
|
||||||
项目根目录创建components文件夹,并在其中创建Header.js
|
创建文件`./pages/_document.js`
|
||||||
```jsx
|
```jsx
|
||||||
import React from 'react'
|
import Document, { Html, Head, Main, NextScript } from 'next/document'
|
||||||
import Head from 'next/head'
|
|
||||||
|
|
||||||
const Header = () => (
|
class MyDocument extends Document {
|
||||||
<div className="header">
|
static async getInitialProps(ctx) {
|
||||||
<Head>
|
const initialProps = await Document.getInitialProps(ctx)
|
||||||
<title></title>
|
return { ...initialProps }
|
||||||
<meta name="viewport" content="initial-scale=1.0, width=device-width" />
|
}
|
||||||
<script>
|
|
||||||
{
|
|
||||||
`
|
|
||||||
with(document)0[(getElementsByTagName('head')[0]||body).appendChild(createElement('script')).src='http://publicjs.supmiao.com/live2dcubismcore.min.js'];
|
|
||||||
`
|
|
||||||
}
|
|
||||||
|
|
||||||
</script>
|
render() {
|
||||||
</Head>
|
return (
|
||||||
</div>
|
<Html>
|
||||||
)
|
{/* <Head /> */}
|
||||||
|
<Head>
|
||||||
|
<script src = "http://publicjs.supmiao.com/live2dcubismcore.min.js"></script>
|
||||||
|
</Head>
|
||||||
|
<body>
|
||||||
|
<Main />
|
||||||
|
<NextScript />
|
||||||
|
</body>
|
||||||
|
</Html>
|
||||||
|
)
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
export default Header
|
export default MyDocument
|
||||||
```
|
```
|
||||||
|
|
||||||
```jsx
|
```jsx
|
||||||
import dynamic from 'next/dynamic'
|
import dynamic from 'next/dynamic'
|
||||||
|
|
||||||
|
|
||||||
const DynamicComponentWithNoSSR = dynamic(import('../components/Header'), {
|
|
||||||
ssr: false
|
|
||||||
})
|
|
||||||
|
|
||||||
const ReactLive2d = dynamic(import('react-live2d'), {
|
const ReactLive2d = dynamic(import('react-live2d'), {
|
||||||
ssr: false
|
ssr: false
|
||||||
})
|
})
|
||||||
|
|
||||||
export default function Home() (
|
export default function Home() (
|
||||||
<>
|
<>
|
||||||
<DynamicComponentWithNoSSR></DynamicComponentWithNoSSR>
|
|
||||||
<ReactLive2d
|
<ReactLive2d
|
||||||
width = { 300}
|
width = { 300}
|
||||||
height = { 500}
|
height = { 500}
|
||||||
|
Loading…
Reference in New Issue
Block a user