vuex-crud icon indicating copy to clipboard operation
vuex-crud copied to clipboard

Getting Uncaught (in promise) TypeError: Cannot read property 'toString' of undefined

Open 7met opened this issue 5 years ago • 2 comments

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?

7met avatar Feb 23 '20 21:02 7met

Does your api response contains properties with array? like { name: "John Doe", roles: ["Super Admin", "Admin"] }

jeck5895 avatar May 25 '20 13:05 jeck5895

it seems the error occurs because of response data that contains array properties on the row object image

jeck5895 avatar May 25 '20 13:05 jeck5895