Skip to content

Instantly share code, notes, and snippets.

@timwis
Last active December 19, 2021 15:08
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save timwis/a5d2f30251800086efc1f8ddd8ad80b7 to your computer and use it in GitHub Desktop.
Save timwis/a5d2f30251800086efc1f8ddd8ad80b7 to your computer and use it in GitHub Desktop.
Nested components with v-model
<template>
<b-autocomplete
v-bind="$attrs"
:data="features"
:loading="isLoading"
field="properties.name"
keep-first
@typing="search"
@select="option => selected = option"
>
<template #default="{ option }">
<div>{{ option.properties.name }}</div>
</template>
</b-autocomplete>
</template>
<script>
import debounce from 'lodash/debounce'
export default {
data () {
return {
features: [],
selected: null,
isLoading: false
}
},
methods: {
search: debounce(async function (query) {
if (!query.length) {
this.features = []
return
}
this.isLoading = true
const url = '/traveltime/geocoding/search'
const params = { query }
try {
const data = await this.$axios.$get(url, { params })
this.features = data.features
} catch (error) {
this.features = []
throw error
}
this.isLoading = false
}, 500)
}
}
</script>
<template>
<main class="container">
<fieldset>
<form>
<b-field label="Your location">
<LocationInput
v-model="yourLocation"
name="yourLocation"
icon="map-marker"
/>
</b-field>
<b-field label="Their location">
<LocationInput
v-model="theirLocation"
name="theirLocation"
icon="map-marker"
/>
</b-field>
</form>
</fieldset>
</main>
</template>
<script>
import LocationInput from '@/components/LocationInput'
export default {
name: 'SearchPage',
components: {
LocationInput
},
data () {
return {
yourLocation: {},
theirLocation: {}
}
}
}
</script>
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment