javascript - 我如何在反应中包含第三方库(turn.js)
问题描述
现在,我需要在 react 中做翻页动画。我看到了用于翻页的 turn.js 库。我在反应组件中导入了它。它没有调用该库中的 Jquery 函数(.turn)
进口声明
import React from 'react';
import $ from 'jquery'
import 'turn.js/index.js'
Oncomponent 做了 mount 方法:
componentDidMount(){
$("#flipbook").turn({
width: 400,
height: 300,
autoCenter: true
});
}
渲染时:
<div>
<div ref="flipbook">
<div className="hard"> Turn.js </div>
<div className="hard"></div>
<div> Page 1 </div>
<div> Page 2 </div>
<div> Page 3 </div>
<div> Page 4 </div>
<div className="hard"></div>
<div className="hard"></div>
</div>
</div>
浏览器控制台中的错误:
</p>
Turn.js?36f0:16 Uncaught TypeError: jquery__WEBPACK_IMPORTED_MODULE_1___default(...)(...).turn is not a function
解决方案
为什么不使用 react-flip-page。它很好而且反应灵敏。
使用 npm 安装它:
npm install --save react-flip-page
然后你可以FlipPage
作为一个组件使用。像这样:
<FlipPage>
<article>
<h1>My awesome first article</h1>
<p>My awesome first content</p>
</article>
<article>
<h1>My wonderful second article</h1>
<p>My wonderful second content</p>
</article>
<article>
<h1>My excellent third article</h1>
<p>My excellent third content</p>
</article>
</FlipPage>
推荐阅读
- java - 对 Lambda 对象的方法调用返回值
- perl - Perl - 使用带有编码 URL 的 Mojolicious::Plugin::OpenAPI
- python - 如何从具有唯一键和值的字典中创建数据框作为列表?
- javascript - 在 JS 中的 agGrid 中显示二维数组
- amazon-web-services - 我如何调试使用 AuthorizerConfigurationException 产生错误的 aws lambda 授权程序
- java - 如何确保多次单击单个按钮不会重复结果?
- javascript - React.JS 中的 jquery“this”选择器替换
- html - 如何解决 CSS 链接问题
- c# - GoogleOAuth2AuthenticationHandler + SSL 终止 - redirect_uri_mismatch
- javascript - Vue.js 中带有观察者的动画 Int 到 Int 变化