我想在商店設(shè)置變量。這是我的商店class storeCategory{ @observable categories =[]; @action getCategories = () =>{ fetch('http://localhost:3000/categories') .then((resp) => resp.json()) .then(function(resp2){ this.categories=resp2; }); }}這是我的組件@inject('sCategory')@observerclass Category extends React.Component{ componentDidMount=()=>{ this.props.sCategory.getCategories(); } render(){ const {sCategory} = this.props; return ( <ListGroup> {this.props.sCategory.categories.map((cat, index) => { return ( <ListGroupItem key={cat.id}>{cat.categoryName}</ListGroupItem> ) })} </ListGroup> ); }}我在 index.js中將 sCategory添加到Provider我在 fetch 方法中的this.categories=resp2處收到此錯誤;無法設(shè)置未定義的屬性“類別”
無法設(shè)置未定義的屬性“x”
慕慕森
2021-11-18 16:01:04