鍍金池/ 問答/Java  PHP  Python  HTML/ v-for 的時候 ,怎么得到當前check= true,的value值,發(fā)下代

v-for 的時候 ,怎么得到當前check= true,的value值,發(fā)下代碼

問題

我一點擊就全部選中了,我想點擊當前的時候,得到當前的value值
clipboard.png

clipboard.png

<template>
    <div>
        <div v-for="item in testData" :key="item.id">
            <input type="checkbox" :checked="item.value"  :value="item.value" v-model="checkedNames">
            <label :for="item.value">{{item.value}}</label>
        </div>
        <span>選擇的值為: {{ checkedNames }}</span>
    </div>

</template>


<script>
export default {
    data() {
        return {
            checkedNames: "",
            testData: [
                { id: 1, value: "jie" },
                { id: 2, value: "biao" },
                { id: 3, value: "nine" }
            ]
        };
    }
};
</script>

回答
編輯回答
鹿惑

其實你可以不用checked的。
動態(tài)的class類名

<li v-for="key,index in testData" @click="selected(key.value,index)" :class="select==index">
selected(val1,val2){
    this.select=val2;
    console.log(val2)//當前點擊的元素對應的value值
}


2018年4月27日 00:34