我是一个非常新的反应者,我发现解决错误的困难。当我使用npm start运行代码时,将显示下拉列表,但是当我使用npm run build构建代码时,将引发错误。我需要帮助。
错误:无法加载资源:服务器响应状态为404(未找到) CountrySearch.js:18未捕获(承诺)语法错误:JSON中位置0处的意外令牌< 在CountrySearch.js:18
Country.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>
)
}
}
CountrySearch.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>
);
}