<template>
<div>
<label>
Switch:
<input type="checkbox" v-model="isChecked">
</label>
<p>当前状态: {{ isChecked ? '开启' : '关闭' }}</p>
</div>
</template>
<script>
export default {
data() {
return {
isChecked: false
};
}
};
</script>
<style scoped>
/* 添加一些样式以增强视觉效果 */
input[type="checkbox"] {
appearance: none;
width: 40px;
height: 20px;
background: #ccc;
border-radius: 10px;
position: relative;
outline: none;
transition: background 0.3s;
}
input[type="checkbox"]:after {
content: '';
position: absolute;
top: 2px;
left: 2px;
width: 16px;
height: 16px;
background: white;
border-radius: 50%;
transition: left 0.3s;
}
input[type="checkbox"]:checked {
background: #4caf50;
}
input[type="checkbox"]:checked:after {
left: 20px;
}
</style>
模板部分 (<template>):
label 标签来包裹一个复选框 (input[type="checkbox"]) 和一段文本。v-model 指令与 isChecked 数据属性进行双向绑定。isChecked 的值显示不同的文本。脚本部分 (<script>):
data 函数中返回了一个初始为 false 的 isChecked 属性。样式部分 (<style scoped>):
上一篇:vue checkbox
下一篇:vue阻止冒泡
Laravel PHP 深圳智简公司。版权所有©2023-2043 LaravelPHP 粤ICP备2021048745号-3
Laravel 中文站