1 回答
TA贡献1784条经验 获得超8个赞
<!DOCTYPE html>
<html>
<head>
<meta charset="UTF-8">
<title></title>
<style type="text/css">
</style>
</head>
<body>
<div id="box">
<div v-for="(item, index) in items" :key="index">
<div class="user-sex">
<label><input ref="man" type="radio" name="sex" :checked="item.val" @change="change">
<i></i>男</label>
<label><input ref="woman" type="radio" name="sex" @change="change" :checked="!item.val">
<i></i>女</label>
</div>
</div>
<button @click="sub">提交</button>
</div>
<script src="vue.js"></script>
<script>
var vm = new Vue({
el:"#box",
data:{
items:[{val:true,sex:0}]
},
methods:{
sub:function(){
console.log(this.items[0].sex);
},
change:function(){
this.items[0].sex = (!this.items[0].sex==true)?1:0;
}
}
});
</script>
</body>
</html>
添加回答
举报