Im a newbie in Vue Js. The problem is on selecting an dropdown from form,options are coming in form of checkbox in a div,on selecting of checkbox, chips should display with the checkbox label.But here checkbox is automatically getting selected and chips are getting displayed,But after selecting an checkbox chips should display and on closing the chips checkbox should get Deselect.This is expected but not happening.Here is the my code.Kindly help.
<template>
<div id="app">
<v-layout row wrap>
<v-flex v-for="chip in chips" xs12 sm4 md4>
<v-checkbox :label="chip.name" v-model="chip.text"></v-checkbox>
// checkbox not working
</v-flex>
<div class="text-xs-center">
<v-select
:items="dataArr"
v-model="sensorDM"
label="Select"
class="input-group--focused"
item-value="text"
v-change="call(sensorDM)"
></v-select>
<v-chip
v-for="tag in chips"
:key="tag.id"
v-model="tag.text"
close
>
{{ tag.name }}
</v-chip>
<br>
</div>
</div>
</template>
<script>
import axios from 'axios'
export default {
name: 'Creation',
data: () => ({
chips: [{
id: 1, text: 'Device 1', name: 'Device 1'
}, {
id: 2, text: 'Device2', name: 'Device 2'
}],
chip1: false,
chip2: true,
dataArr: []
}),
created () {
let self = this
axios.get('http://localhost:4000/api/devices')
.then(function (response) {
self.fData(response.data.result)
})
},
methods: {
fData: function (message) {
let self = this
message.forEach(function (el, i) {
self.dataArr.push(el.sDM.name)
})
},
call (mes) {
let self = this
axios.get('http://localhost:4000/api/part1/Models/' + mes)
.then(function (res) {
self.resObj = res.data.response
self.resObj.forEach(function (el, i) {
el['text'] = el.name
el['isOpen'] = 'false'
})
self.chips = self.resObj
})
},
submit(){
console('hjkh')
}
}
}
Hi I have edited the code and added the function call from created()
I guess you want to do like this https://codepen.io/ittus/pen/VxGjgN
I added
selected
attribute, because by default v-checkbox and v-chip value are boolean.I just super simplified your codepen to show how to do this:
https://codepen.io/anon/pen/qYMNxy?editors=1010
HTML:
JS:
For you the checkboxes are always selected because your v-model is bound to the chip.text. I added a selected property to the chips so that you can bind to chip.selected.
I hope this helps!
Also a tip from my side, the guides from vue.js are super helpful and really nicely documented, please check them out:
https://vuejs.org/v2/guide/forms.html
kr, Georg
I tried one last time to understand your usecase and to show you in a very simplified version without vuetify and axios how to achieve what I think you want to achieve.
https://codepen.io/anon/pen/LmJoYV?editors=1010
HTML:
JS: