Skip to content

Commit

Permalink
Added Restful conditional (pespantelis#22)
Browse files Browse the repository at this point in the history
* Added Restful conditional

* src/main.js

* doc update

* changed to instead if queryParamName is null

* forgot to remove isrestful
  • Loading branch information
weklund authored and pespantelis committed Jun 30, 2016
1 parent eb44a12 commit f39e734
Show file tree
Hide file tree
Showing 2 changed files with 11 additions and 6 deletions.
1 change: 1 addition & 0 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -73,6 +73,7 @@ export default {
minChars: 3,
// Override the default value (`q`) of query parameter name
// ** If null, will assume you are making a restful query instead **
// (optional)
queryParamName: 'search'
}
Expand Down
16 changes: 10 additions & 6 deletions src/main.js
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
import { util } from 'vue'
import {util} from 'vue'

export default {
data () {
Expand All @@ -7,7 +7,7 @@ export default {
query: '',
current: -1,
loading: false,
queryParamName: 'q'
queryParamName: null
}
},

Expand Down Expand Up @@ -57,11 +57,15 @@ export default {
return util.warn('You need to set the `src` property', this)
}

let queryParam = {
[this.queryParamName]: this.query
if (this.queryParamName == null) {
return this.$http.get(this.src + this.query)
} else {
let queryParam = {
[this.queryParamName]: this.query
}
return this.$http.get(this.src, Object.assign(queryParam, this.data))
}

return this.$http.get(this.src, Object.assign(queryParam, this.data))
},

reset () {
Expand Down Expand Up @@ -97,7 +101,7 @@ export default {
},

down () {
if (this.current < this.items.length-1) {
if (this.current < this.items.length - 1) {
this.current++
} else {
this.current = -1
Expand Down

0 comments on commit f39e734

Please sign in to comment.