diff --git a/src/component/QsSelect.json b/src/component/QsSelect.json index c47954e..b6dcdde 100644 --- a/src/component/QsSelect.json +++ b/src/component/QsSelect.json @@ -431,7 +431,7 @@ "desc": "Select all the options; Available only when multiple." }, "fetchOptions": { - "desc": "Fetch and update the options" + "desc": "Fetch the options; Available only when lazy." }, "only": { "desc": "Select only one option; Available only when multiple.", diff --git a/src/component/QsSelect.vue b/src/component/QsSelect.vue index 66c5e75..33bbad7 100644 --- a/src/component/QsSelect.vue +++ b/src/component/QsSelect.vue @@ -126,6 +126,10 @@ export default { } }, + async created () { + this.value && this.isLazy && this.setOptions(await this.fetchOptions({ id: this.value })) + }, + computed: { selectProps () { return { @@ -190,18 +194,19 @@ export default { this.opts = parse ? this.parseOptions(options) : options }, resetOptions () { this.setOptions(this.options) }, - async fetchOptions () { - this.loading = true - this.isLazy && this.setOptions(await this.getOptions()) - this.loading = false - }, async prepareOptions () { if (this.options.length > 0) this.resetOptions() - else await this.fetchOptions() + else if (this.isLazy) this.setOptions(await this.fetchOptions()) }, - async getOptions () { - const params = { [this.url.filterParam || 'filter']: this.needle, ...this.url.filters } + async fetchOptions (other = {}) { + this.loading = true + const params = { + [this.url.filterParam || 'filter']: this.needle, + ...this.url.filters, + ...other + } const { data } = await this.url.instance(this.url.route, { params }) + this.loading = false return data }, parseOptions (options) {