0

我很新的反应,我发现难以解决错误。当我使用 npm start 运行我的代码时,会显示下拉列表,但是当我使用 npm run build 构建我的代码时,它会引发错误。我需要帮助。

错误:加载资源失败:服务器响应状态为 404(未找到) CountrySearch.js:18 未捕获(承诺中) SyntaxError: Unexpected token < in JSON at position 0 at CountrySearch.js:18

国家.js

class Country extends React.Component {
    constructor() {
        super();
    }

    render () {
        let countries = this.props.state.countries;
        let optionItems = countries.map((country) =>
                <option key={country.COUNTRY_NAME}>{country.COUNTRY_NAME}</option>
            );

        return (
         <div>
             <select className="DrpDownSelectstyle">
                {optionItems}
             </select>
         </div>
        )
    }
}

国家搜索.js

import Country from './Country';

class CountrySearch extends Component {
    constructor() {
        super();
        this.state = {
            countries: [],
        };
    }

componentDidMount() {
    let initialCountry = [];
    fetch('/wwsnr/webservices/pswebapi/api/GetCountries')
        .then(response => {
        return response.json();
        })
        .then(json => {
        initialCountry = json.map((country) => {
            return country
        });
        console.log(initialCountry);
        this.setState({
            countries: initialCountry,
        });
    });
}

render() {
    return (
        <div>
            <i><b>Search a country or region:</b></i>
            <div className="List">
                <Country state={this.state}/>
            </div>
        </div>

    );
}
4

0 回答 0