<!DOCTYPE html>
<html lang="zh">
<head>
    <meta charset="UTF-8">
    <meta name="viewport" content="width=device-width, initial-scale=1.0">
    <meta http-equiv="X-UA-Compatible" content="ie=edge">
    <script src="https://cdn.jsdelivr.net/npm/vue@2.6.12"></script>
    <title>Vue自学:v-model结合checkbox类型使用</title>
</head>
<body>
    <div id="app">
        <label for="male">
            <!-- for要求指向id值,绑定一个ID  Value值必须设置,否则v-model会报错 -->
            <input type="radio" name="" id="male" value="男" v-model="sex"/>男
        </label>
        <label for="famale">
            <input type="radio" name="" id="famale" value="女" v-model="sex" />女
        </label>
        <h2>你的性别是:{{sex}}</h2>
    </div>
</body>
<script type="text/javascript">
    const app = new Vue({
        el:’#app’,
        data:{
            message:’你好啊’,
            //当设置sex为男的时候,则默认值为男
            sex:’男’,
        },
        methods:{
        }
    })
</script>
</html>
                Copyright 2014-2025 https://www.php.cn/ All Rights Reserved | php.cn | 湘ICP备2023035733号