Last active
December 19, 2021 15:08
-
-
Save timwis/a5d2f30251800086efc1f8ddd8ad80b7 to your computer and use it in GitHub Desktop.
Nested components with v-model
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
<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> |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
<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