Skip to content

Instantly share code, notes, and snippets.

@tporto
Created November 5, 2019 18:14
Show Gist options
  • Save tporto/59684fbbc85f9c898f6d46fcc52cd8c9 to your computer and use it in GitHub Desktop.
Save tporto/59684fbbc85f9c898f6d46fcc52cd8c9 to your computer and use it in GitHub Desktop.
<template>
<div>
<button @click="status = !status">change status</button> {{ status }}
<br>
<div v-for="m in marcas">
<input type="checkbox" :value="m.id" v-model="checkedNames" v-on:click="click_marca(m.id)" /> {{ m.nome }}
</div>
<ul>
<li v-for="m in marcas">
{{ m.nome }}
</li>
</ul>
{{ marcas }}
{{ checkedNames }}
{{ modelos }}
</div>
</template>
<script>
import axios from 'axios';
export default {
data() {
return {
status: false,
marcas: [],
modelos: [],
checkedNames: []
}
},
methods: {
click_marca: function(value) {
alert(this.checkedNames);
axios.get('/api/modelos/' + Array.from(this.checkedNames)).then(response => (this.modelos = response.data.data))
}
},
mounted() {
axios.get('/api/marcas').then(response => (this.marcas = response.data.data))
}
}
</script>
@tporto
Copy link
Author

tporto commented Nov 5, 2019

Ao clicar no checkbox quero obter o arrary "checkedNames" no metodo, mas ele só vem atualizado após o segundo clique.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment