1👍
✅
So from this code, If you need to get the data from API on “Create” hook, there are three possible solutions,
- you should not define items as a prop but instead in data.
OR
- If you really need items as a prop, you should make this API Call inside parent of this component and then pass the response data in items prop
OR
-
with this code, you can pass a method to the component and this component can emit that method with the new data. and that method in parent can update the items array. example is given below
<this-component :items=”items” @apiResponse=”(newData) => items = newData” />
and inside this component
created() {
axios.get(API_BASE_URL + '/novels').then(response => {
this.novels = response.data.data
})
this.$emit('apiResponse', this.novels)
this.isLoading = false
},
Source:stackexchange.com