【发布时间】:2019-08-27 07:13:26
【问题描述】:
我想用 react 运行 turn.js。我在这里找到了一个例子: https://codesandbox.io/s/005xlk45mn
我将代码改编为我的项目,但出现以下错误: TypeError: jquery__WEBPACK_IMPORTED_MODULE_6___default(...)(...).turn 不是函数
import React, { Component } from 'react';
import $ from "jquery";
import "turn.js";
const options = {
width: 800,
height: 600,
autoCenter: true,
display: "double",
acceleration: true,
elevation: 50,
gradients: !$.isTouch,
when: {
turned: function(e, page) {
console.log("Current view: ", $(this).turn("view"));
}
}
};
class xxx extends Component {
constructor(props) {
super(props);
}
componentDidMount() {
$("#flipbook").turn(options);
}
render() {
return (
<div id="flipbook">
<div className="hard">Turn.js</div>
<div className="hard"></div>
<div> Page 1 </div>
<div> Page 2 </div>
<div className="hard"></div>
<div className="hard"></div>
</div>
);
}
}
export default Condolences;
这也没有用:
import * as $ from "jquery"
componentDidMount() {
$(this.el).turn();
}
render() {
return (
<div id="flipbook" ref={ el => this.el = el }>
<div className="hard">Turn.js</div>
<div className="hard"></div>
<div> Page 1 </div>
<div> Page 2 </div>
<div className="hard"></div>
<div className="hard"></div>
</div>
);
}
【问题讨论】:
-
我需要帮助 :(
标签: javascript jquery reactjs turn.js