vuex-crud
vuex-crud copied to clipboard
Getting Uncaught (in promise) TypeError: Cannot read property 'toString' of undefined
I am trying to get a fetchSingle and getting an error when running the script.
Here is my vue file contents:
<script>
import { mapGetters, mapActions, mapState } from 'vuex';
export default {
name: 'tag',
computed: {
...mapGetters('tags', {
tagById: 'byId'
}),
...mapState([
'route', // vuex-router-sync
]),
currentTag() {
return this.tagById(this.$route.params.id);
}
},
methods: {
...mapActions('tags', {
fetchTag: 'fetchSingle'
}),
fetchData() {
return this.fetchTag({
id: this.$route.params.id
});
}
},
watch: {
$route: 'fetchData',
},
created() {
this.fetchData();
}
};
</script>
CreateMutations.js
fetchSingleSuccess: function fetchSingleSuccess(state, response) {
var data = response.data;
var id = data[idAttribute].toString(); <-- causes the error
Any ideas?
Does your api response contains properties with array? like { name: "John Doe", roles: ["Super Admin", "Admin"] }
it seems the error occurs because of response data that contains array properties on the row object