v-model结合checkbox

单选

<body>
    <div id="app">
        <label for="agree">
            <input type="checkbox"  v-model="agree" id="agree" >同意协议
        </label>
        
        <button :disabled="!agree">下一步</button>
        {{agree}}
    </div>
    <script src="https://cdn.jsdelivr.net/npm/vue/dist/vue.js"></script>
    <script>
        new Vue({
            el:'#app',
            data:{
                agree: false

            }
        })
    </script>
</body>

v-model结合checkbox

 

 

 

多选

<body>
    <div id="app">
        <input type="checkbox" value="篮球" v-model="hobbies">篮球
        <input type="checkbox" value="乒乓球" v-model="hobbies">乒乓球
        <input type="checkbox" value="羽毛球" v-model="hobbies">羽毛球
        <input type="checkbox" value="台球" v-model="hobbies">台球
        
        <br>您已选择:{{hobbies}}
    </div>
    <script src="https://cdn.jsdelivr.net/npm/vue/dist/vue.js"></script>
    <script>
        new Vue({
            el:'#app',
            data:{
                hobbies: []

            }
        })
    </script>
</body>

v-model结合checkbox

 

 

 

 

多选(常用写法)

<body>
    <div id="app">
        <label v-for="item in hobbies">
            <input type="checkbox" :value="item" v-model="hobby">{{item}}
        </label>
        
        <br>您已选择:{{hobby}}
    </div>
    <script src="https://cdn.jsdelivr.net/npm/vue/dist/vue.js"></script>
    <script>
        new Vue({
            el:'#app',
            data:{
                hobbies: ['篮球','乒乓球','羽毛球','台球'],//后台返回
                hobby:[]
            }
        })
    </script>
</body>

 

 

v-model结合checkbox

 

上一篇:【DB笔试面试445】Oracle中的异常可以分为哪几类?


下一篇:stark组件前戏之django路由分发的本质