Skip to content
This repository has been archived by the owner on Dec 5, 2024. It is now read-only.

help: useFetch - Cannot read property 'isPreview' of undefined #143

Closed
Denoder opened this issue Jul 3, 2020 · 6 comments
Closed

help: useFetch - Cannot read property 'isPreview' of undefined #143

Denoder opened this issue Jul 3, 2020 · 6 comments
Assignees

Comments

@Denoder
Copy link

Denoder commented Jul 3, 2020

📚 What are you trying to do? Please describe.
I was trying to transition into using the composition API and was going to use fetch but when I use it i get this error:

TypeError: Cannot read property 'isPreview' of undefined

🔍 What have you tried?
This was my previous apprach before composition:

    async fetch () {
        this.getEpisodes();
    },
    activated () {
        // Call fetch again if last fetch more than 30 sec ago
        if (this.$fetchState.timestamp <= (Date.now() - 60000)) {
            this.$fetch()
        }
    }, 

this is my new approach in transtition:

        const { $fetch, $fetchState } = useFetch(async () => {
            getEpisodes()
        })

        onActivated(() => {
            // Call fetch again if last fetch more than 30 sec ago
            if ($fetchState.timestamp <= (Date.now() - 60000)) {
                $fetch()
            }
        })

ℹ️ Additional context
The getEpisodes method:

        let getEpisodes = async function (page) {
            const { data, meta } = await $axios.$get('/api/shows/details/episodes',  { params: { id: params.value.id, page: page } });

            info.episodes = data;
            info.pagination = {
                current_page: meta.current_page,
                last_page: meta.last_page,
                total: meta.total,
                per_page: meta.per_page,
                from: meta.from,
                to: meta.to
            }
        }

Upon looking fetch would be called client side and does call the getEpisodes method so i think it has to be something server sided

@Denoder Denoder changed the title help: help: useFetch - Cannot read property 'isPreview' of undefined Jul 3, 2020
@danielroe
Copy link
Member

@teranode I think this should be fixed in 0.10.4, but do let me know if you have any issues.

@Denoder
Copy link
Author

Denoder commented Jul 9, 2020

@danielroe It renders now, but the isPreview Error is still present in the console logs when it's used.

@danielroe
Copy link
Member

What version of Nuxt are you using?

@Denoder
Copy link
Author

Denoder commented Jul 9, 2020

im using 2.13.3

danielroe added a commit that referenced this issue Jul 9, 2020
@danielroe
Copy link
Member

Any better luck with 0.10.5?

@Denoder
Copy link
Author

Denoder commented Jul 9, 2020

Yes, that fixed it

Sign up for free to subscribe to this conversation on GitHub. Already have an account? Sign in.
Labels
None yet
Projects
None yet
Development

No branches or pull requests

2 participants