超全模态模型 × Harness 升级,升级解锁 ArkClaw,最新支持 DeepSeek-V4 系列与 GLM-5.1
<object>
onError
onLoadedMetadata
onLoadedData
通过React的ref获取<object>元素实例,在组件挂载后手动添加原生事件监听,卸载时移除监听避免内存泄漏:
ref
class MyPDF extends React.Component { constructor(props) { super(props); this.state = { errorMsg: null }; this.objectRef = React.createRef(); this.onDocumentErrorLoad = this.onDocumentErrorLoad.bind(this); this.handleLoad = this.handleLoad.bind(this); } componentDidMount() { const objectEl = this.objectRef.current; if (objectEl) { // 绑定原生错误事件 objectEl.addEventListener('error', this.onDocumentErrorLoad); // 绑定原生加载完成事件(替代onLoadedMetadata) objectEl.addEventListener('load', this.handleLoad); } } componentWillUnmount() { const objectEl = this.objectRef.current; if (objectEl) { // 移除事件监听,防止内存泄漏 objectEl.removeEventListener('error', this.onDocumentErrorLoad); objectEl.removeEventListener('load', this.handleLoad); } } setErrorMsg(msg) { this.setState({ errorMsg: msg }); } onDocumentErrorLoad(event) { console.log("fine1"); this.setErrorMsg("Error: " + event.message); } handleLoad(event) { console.log("fine2"); // 此处可处理PDF加载完成后的逻辑 } render() { return ( <> {this.state.errorMsg && <div>{this.state.errorMsg}</div>} <object ref={this.objectRef} height="500" data={"httpssss://gooogle.come"} type="application/pdf" /> </> ); } }
如果需要更稳定的PDF加载、渲染和事件处理,推荐使用react-pdf这类封装好的库,它基于PDF.js实现,能可靠触发各类加载事件:
react-pdf
import { Document, Page } from 'react-pdf'; class MyPDF extends React.Component { state = { errorMsg: null, numPages: null, }; onDocumentLoadSuccess = ({ numPages }) => { this.setState({ numPages }); console.log("PDF加载成功,总页数:", numPages); }; onDocumentLoadError = (error) => { this.setState({ errorMsg: error.message }); console.log("fine1", error); }; render() { const { errorMsg, numPages } = this.state; return ( <> {errorMsg && <div>{errorMsg}</div>} <Document file={"httpssss://gooogle.come"} onLoadSuccess={this.onDocumentLoadSuccess} onLoadError={this.onDocumentLoadError} > <Page pageNumber={1} /> </Document> </> ); } }
内容的提问来源于stack exchange,提问作者samUser1
超全模态模型 × Harness 升级,最新支持 Deepseek-V4.1-Flash、GLM-5.3 系列、Doubao-Seedream-5.0-pro、Kimi-K3 (部分), 限时 9.9 元起
模型再升级,30秒超长叙事, 模态参考扩容
模型自由,工具不限,最新支持 Deepseek-V4 系列、GLM-5.3 系列
超全模态模型 × Harness 升级,最新支持 Deepseek-V4.1-Flash、GLM-5.3 系列
大模型19元起,Al应用9.9元畅享,新人首购爆款尽享优惠