Skip to content

Commit

Permalink
refactor
Browse files Browse the repository at this point in the history
  • Loading branch information
cirolosapio committed Jun 29, 2020
1 parent f75d209 commit 0cd013b
Show file tree
Hide file tree
Showing 2 changed files with 14 additions and 9 deletions.
2 changes: 1 addition & 1 deletion src/component/QsSelect.json
Original file line number Diff line number Diff line change
Expand Up @@ -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.",
Expand Down
21 changes: 13 additions & 8 deletions src/component/QsSelect.vue
Original file line number Diff line number Diff line change
Expand Up @@ -126,6 +126,10 @@ export default {
}
},
async created () {
this.value && this.isLazy && this.setOptions(await this.fetchOptions({ id: this.value }))
},
computed: {
selectProps () {
return {
Expand Down Expand Up @@ -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) {
Expand Down

0 comments on commit 0cd013b

Please sign in to comment.