请稍等 ...
×

采纳答案成功!

向帮助你的同学说点啥吧!感谢那些助人为乐的人

import PropTypes from 'prop-types'; 引入PropTypes之后 为什么编译失败了?

Failed to compile
./src/JS/Items.js
SyntaxError: C:\Users\XD\my-app\src\JS\Items.js: Unexpected token (26:13)

24 | }
25 |

26 | Items.propTypes = {
| ^
27 | content: PropTypes.string,
28 | index: PropTypes.number,
29 | handleItemDelete: PropTypes.func

正在回答 回答被采纳积分+3

2回答

提问者 慕莱坞2689431 2020-11-14 16:51:42

import React, { Component } from 'react';

import PropTypes from 'prop-types';              



class Items extends Component {

        constructor(props) {

                super(props);

                this.handClick = this.handClick.bind(this)

        }


        render() {

                const { content } = this.props;       

                return <div onClick={this.handClick}>

                        {content}

                </div>

        }


        handClick() {

                const { index, handleItemDelete } = this.props;   

                handleItemDelete(index);

                

        }


        Items.propTypes  = {   

                content: PropTypes.arrayOf(PropTypes.string, PropTypes.number),

                index: PropTypes.number.isRequired,        

                handleItemDelete: PropTypes.func


        }


}


0 回复 有任何疑惑可以回复我~
  • Dell #1
    import React, { Component } from 'react';
    
    import PropTypes from 'prop-types';              
    
    
    
    
    class Items extends Component {
    
            constructor(props) {
    
                    super(props);
    
                    this.handClick = this.handClick.bind(this)
    
            }
    
    
    
            render() {
    
                    const { content } = this.props;       
    
                    return <div onClick={this.handClick}>
    
                            {content}
    
                    </div>
    
            }
    
    
    
            handClick() {
    
                    const { index, handleItemDelete } = this.props;   
    
                    handleItemDelete(index);
    
                    
    
            }
    
    }
    
    Items.propTypes  = {   
    
                    content: PropTypes.arrayOf(PropTypes.string, PropTypes.number),
    
                    index: PropTypes.number.isRequired,        
    
                    handleItemDelete: PropTypes.func
    
    
    
            }
    回复 有任何疑惑可以回复我~ 2020-11-18 00:46:04
  • Dell #2
    这么写
    回复 有任何疑惑可以回复我~ 2020-11-18 00:46:12
Dell 2020-11-14 16:01:09

你代码贴上来我看看大,语法感觉写的有问题

0 回复 有任何疑惑可以回复我~
问题已解决,确定采纳
还有疑问,暂不采纳
意见反馈 帮助中心 APP下载
官方微信