-1
Hello! I’m studying And at the same time trying to apply what I’m learning in a project.
A difficulty has arisen. I have a list of checkboxes with the brands of the vehicles, when I click will load the models of the selected brands, and I wish that when loading the models come the brand name first and below the models.
Ex:
Chevrolet
- Onix
- Cousin
FORD
- Goal
- Golf
<template>
<div>
<div v-show="marcas.length">
<h5>Marcas de interesse</h5>
<hr>
<div class="form-group form-check">
<div v-for="m in marcas">
<input name="cliente_interessado[marca][]" class="form-check-input" type="checkbox" :value="m.id" v-on:click="clickMarca(m.id)" >
<label class="form-check-label">{{ m.nome }}</label>
</div>
</div>
</div>
<div v-if="loading">Carregando...</div>
<div v-show="modelos.length">
<br>
<h5 >Modelos de interesse</h5>
<hr>
<div class="form-group form-check">
<div v-for="m in modelos">
<input name="cliente_interessado[modelo][]" class="form-check-input" type="checkbox" :value="m.id" >
<label class="form-check-label">{{ m.marca }} - {{ m.nome }}</label>
</div>
</div>
</div>
</div>
</template>
<script>
import axios from 'axios';
export default {
data() {
return {
marcas: [],
modelos: [],
checkedNames: [],
loading: false,
}
},
created() {
axios.get('/api/marcas').then(response => (this.marcas = response.data.data))
},
methods: {
clickMarca(value) {
if (this.checkedNames.find(item => item === value)) {
var pos = this.checkedNames.indexOf(value);
this.checkedNames.splice(pos, 1);
} else {
this.checkedNames.push(value)
}
this.loading = true
axios.get('/api/modelos/' + "[" + this.checkedNames.toString() + "]")
.then(response => (this.modelos = response.data.data))
.finally(() => this.loading = false)
}
}
}
</script>
cannot create the templates inside the tags object?
– flourigh