我是 React 新手,并按照本教程将 Drag'n'Drop 添加到我的应用程序
我正在按照教程一步一步地创建一个带有可拖动骑士棋子的棋盘,但无法让它工作(仍然无法拖动骑士)
// imports
var {DragSource, DragDropContext} = ReactDnD;
var knightSource = {
beginDrag: function (props) {
return {};
}
};
function collect(connect, monitor) {
return {
connectDragSource: connect.dragSource(),
isDragging: monitor.isDragging()
}
}
var Knight = DragSource("knight", knightSource, collect)(React.createClass({
render() {
var style = {
cursor: 'move',
fontSize: 25
}
return(
<div style={style}>♘</div>
);
}
}));
var Board = DragDropContext(HTML5Backend)(React.createClass({
render() {
var style = {
width: '500px',
height: '500px',
border: '1px solid black',
boxShadow: '4px 2px 2px black'
}
return (
<div style={style}>
<Knight/>
</div>
);
}
}));
ReactDOM.render(
<Board/>,
document.getElementById('ex13')
);
});
谁能解释我做错了什么?