Reactでmaterialize-cssを使用する際に問題があります。私はWebpackとBabelを使って構築しました。問題は次のとおりです。MaterializeがReact、Webpackaで動作していません。 jQueryが拡張されていません
plugins: [
new webpack.ProvidePlugin({
$: "jquery",
jQuery: "jquery"
})
これは一部です:これはjQueryのをインポート私webpack.config.jsの一部である
import React from 'react';
import 'materialize-css';
import 'materialize-css/dist/css/materialize.min.css';
class AwesomeComponent extends React.Component {
constructor(props) {
super(props);
}
onLike() {
$('.modal').modal();
}
render() {
return (
<div>
<div id="modal1" className="modal">
<div className="modal-content">
<h4>Modal Header</h4>
<p>A bunch of text</p>
</div>
<div className="modal-footer">
<a href="#!" className=" modal-action modal-close waves-effect waves-green btn-flat">Agree</a>
</div>
</div>
<a className="waves-effect waves-light btn" onClick={this.onLike}>
<i className="material-icons left">
cloud
</i>
Like cloud
</a>
</div>
);
}
}
export default AwesomeComponent;
:
TypeError: $(...).parallax is not a function
TypeError: $(...).material_chip is not a function
TypeError: $(...).modal is not a function
etc.
それは私のリアクトクラスです私のパッケージの.json:
"dependencies": {
"babel-core": "^6.18.2",
"babel-loader": "^6.2.8",
"babel-preset-es2015": "^6.18.0",
"babel-preset-react": "^6.16.0",
"materialize-css": "^0.98.0",
"react": "^15.4.1",
"react-dom": "^15.4.1",
"webpack": "^1.13.3",
"jquery": "^2.1.4"
},
aveはすべてを試しました。
私はそれをデバッグしました。これは$ prototypeにプラグイン(.modalなど)を追加しますが、クラスで使用したいときに何とか関数が消えてしまいました。同じ問題で他の人のために
TypeError: $(...).modal is not a function[Learn More] bundle.js:44497:14
onLike
bound onLike
ReactErrorUtils.invokeGuardedCallback
executeDispatch
executeDispatchesInOrder executeDispatchesAndRelease
executeDispatchesAndReleaseTopLevel
forEach forEachAccumulated
EventPluginHub.processEventQueue
runEventQueueInBatch
ReactEventEmitterMixin.handleTopLevel
handleTopLevelImpl
TransactionImpl.perform
ReactDefaultBatchingStrategy.batchedUpdates
batchedUpdates
ReactEventListener.dispatchEvent
bound
は今まであなたをしましたモーダルを表示するには?私は開いているときにエラーが発生しないという点を除いて同様の問題を抱えています。全く何も起こらない。私はあなたと同じ設定をしています。以下の答えはどちらもうまくいきませんでした。また、物質反応Modalは現在破られています。 –