-2
添加3dmodal三個I希望在反應如何導入的反應,我想在網絡
import THREE from 'three';
我使用NPM添加three.js所使用three.js所,但有:三是不確定的;
那麼,如何進口,什麼是錯的
感謝
添加3dmodal三個I希望在反應如何導入的反應,我想在網絡
import THREE from 'three';
我使用NPM添加three.js所使用three.js所,但有:三是不確定的;
那麼,如何進口,什麼是錯的
感謝
目前,threejs無法通過NPM安裝。你應該手動安裝它,將它作爲script
標籤附加在你的html中。 React的一個例子。
import React from 'react'
import scriptLoader from 'react-async-script-loader'
@scriptLoader(['https://cdnjs.cloudflare.com/ajax/libs/three.js/85/three.js'])
export default class ThreeReact extends React.Component {
constructor(props) {
super(props)
}
componentWillReceiveProps ({ isScriptLoaded, isScriptLoadSucceed }) {
if (isScriptLoaded && !this.props.isScriptLoaded) { // load finished
if (isScriptLoadSucceed) {
console.log(THREE)
}
else this.props.onError()
}
}
render() {
return (
<div>
Threejs loaded with React.
</div>
)
}
}
您可能應該澄清'@ scriptLoader'是一個es7語言功能 –
好的,謝謝,你解決了我的問題 – paul