Created
November 28, 2019 00:01
-
-
Save gilbertoalbino/907d5dd8219569dd44c8f5ecb3ade3cf to your computer and use it in GitHub Desktop.
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> | |
<div class="cities"> | |
<div v-for="(city, index) in cities"> | |
<label :for="'city'+ index">Cidade {{ index + 1 }}</label> | |
<input v-focus | |
type="text" | |
:id="'city' + index" | |
v-model="cities[index]" | |
placeholder="Insira outra cidade"> | |
</div> | |
<a @click="addCity" href="#">Adicionar outra cidade [+]</a> | |
</div> | |
</template> | |
<script> | |
Vue.directive('focus', { | |
inserted: (el) => { | |
Vue.nextTick(() => { | |
el.focus(); | |
}); | |
} | |
}); | |
export default { | |
data() { | |
return { | |
cities: [], | |
}, | |
}, | |
methods: { | |
addCity() { | |
this.cities.push(''); | |
}, | |
}, | |
}; | |
</script> | |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment