0

I facing issue with calling multiple function in the fetch hook nuxt provided getting error when I am calling 2 function from fetch with await.

async fetch() {
        await this.fetchData();
        await this.fetchData2();
    },
    methods: {
        fetchData(lang) {
            this.$store.dispatch('getData')
        },
        async fetchData2() {
            let res = await api.getData2();
        },
    }

This is the flow I am using when the project run it giving error

TypeError: Cannot read property 'toLowerCase' of undefined and TypeError: progress.start is not a function

I am using nuxt progress for loading .Please let me know what I am doing wrong

1 Answer 1

2

You are awaiting this.fetchData(), but that is not returning a promise.

You want to add await this.$store.dispatch('getData'). You are also not making use of the lang param.

In other words, I guess the following would work...

async fetch() {
        await this.fetchData();
        await this.fetchData2();
    },
    methods: {
        async fetchData() {
            await this.$store.dispatch('getData')
        },
        async fetchData2() {
            let res = await api.getData2();
        },
    }

(or even just returning this.$store.dispatch('getData') without fetchData being an async fn)

Sign up to request clarification or add additional context in comments.

Comments

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.