gpt4 book ai didi

javascript - 如何在 Vue js 中将 Checkboxes 与 Chips 绑定(bind)(双向绑定(bind))

转载 作者:行者123 更新时间:2023-11-30 14:36:35 26 4
gpt4 key购买 nike

我是 Vue Js 的新手。问题出在从表单中选择下拉菜单时,选项以 div 中复选框的形式出现,在选择复选框时,芯片应显示带有复选框标签。但这里会自动选中复选框并显示芯片,但在选择之后一个复选框筹码应该显示并且在关闭筹码复选框时应该取消选择。这是预期的但没有发生。这是我的代码。请帮助。

   <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')
}
}
}

您好,我已经编辑了代码并添加了来自 created() 的函数调用

最佳答案

我猜你想这样做 https://codepen.io/ittus/pen/VxGjgN

<div id="app">
<v-flex v-for="chip in chips" :key="chip.id" xs12 sm4 md4>
<v-checkbox :label="chip.name" v-model="chip.selected"></v-checkbox>
<v-chip
v-model="chip.selected"
close>
{{ chip.name }}
</v-chip>
</v-flex>
<div class="text-xs-center">
</div>
</div>

new Vue({
el: '#app',
data() {
return {
chips: [{
id: 1, text: 'Device 1', name: 'Device 1', selected: false
}, {
id: 2, text: 'Device2', name: 'Device 2', selected: false
}],
chip1: false,
chip2: true,
}
}
})

我添加了 selected 属性,因为默认情况下 v-checkbox 和 v-chip 值是 bool 值。

关于javascript - 如何在 Vue js 中将 Checkboxes 与 Chips 绑定(bind)(双向绑定(bind)),我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/50350254/

26 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com