Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

New data doesn't rerender when already focused. Bug with async data. #14

Open
JoshMoreno opened this issue Dec 17, 2019 · 0 comments
Open

Comments

@JoshMoreno
Copy link

I'm populating the passing a list of suggestions to the data prop which get set in an async function.

Basically, I have a component that watches search, hits the api, and sets the suggestions which get passed to your component. But your component doesn't update list in your component until you re-trigger a focus event.

Component that uses v-suggest

<template>
    <v-suggest
            v-model="search"
            :data="this.suggestions"
    ></v-suggest>
</template>

<script>
    import { Suggest } from 'v-suggest'
    import axios from 'axios'

    export default {
        components: {
            'v-suggest': CustomVSuggest
        },
        data() {
            return {
                search: '',
                suggestions: [],
            }
        },
        methods: {
            getSuggestions: function() {
                return axios.get('/api/search/' + this.search)
                        .then(response => {
                            this.suggestions = response.data
                        })
            },
        },
        watch: {
            search: function(newValue, oldValue) {
                this.getSuggestions()
            }
        }
    }
</script>

The workaround I'm using right now is creating a component that extends yours and just calls this.focus() whenever data changes. And then of course using this in place of the v-suggest component.

Workaround component

<script>
    import { Suggest } from 'v-suggest'

    export default {
        extends: Suggest,
        watch: {
            data(newValue, oldValue) {
                this.focus()
            }
        }
    }
</script>

I think you can probably just add this to your methods.js

watch: {
    data(newValue, oldValue) {
        this.focus()
    }
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

1 participant