我正尝试在我的NextJS项目中使用react-springy-parallax,但每当我想使用它时,我都会收到以下错误消息:
无法加载webpack://%5Bname%5D_%5Bchunkhash%5D/./node_modules/react-dom/cjs/react-dom.development.js?.的
抓取接口对于CORS请求,URL方案必须为http或https。
这是对NextJS上的react-springy-parallax
的限制吗?
下面是我放在index.js
组件中的示例代码:
<Parallax ref='parallax' pages={3}>
<Parallax.Layer offset={0} speed={0.5}>
<span>Layers can contain anything</span>
</Parallax.Layer>
</Parallax>
这个问题似乎与CORS问题有关,我不知道如何解决这个问题。
发布于 2019-05-31 07:59:50
我读到这与NextJS没有什么特别的关系。在React 16.8.0及更高版本之后,我发现必须使用useRef
函数。
解决方案:
import React, { useRef } from 'react'
[...]
const parallax = useRef( 'parallax' )
[...]
<Parallax ref={ parallax } pages={3}>
<Parallax.Layer offset={0} speed={0.5} onClick={ () => parallax.current.scrollTo(1) }>
<span>Layers can contain anything</span>
</Parallax.Layer>
</Parallax>
https://stackoverflow.com/questions/56371473
复制相似问题