当前位置: 首页 > news >正文

Vue2 -- 自定义单选内容的单选框组件

自定义单选内容的单选框组件

之前做的一个项目,在项目中有一个关于人员权限分配的功能,给人员指定各个模块的权限信息,分为

  • write 可写权限
  • read 可读权限
  • none 没有权限

项目要求画面中只显示 W R 两个按钮控制指定权限信息,都不选择的时候权限为 none

<!-- 
==============================================================================
HTML5
==============================================================================
--><template><div class="checkboxs"><label v-for="(dataItem, i) in dataList" :key="i"><input:id="permissionPhase.slice(0, 1).toUpperCase() + permissionPhase.slice(1) + '_' + dataItem.value.toLowerCase()"type="button"name="permissionCheckbox"class="checkbox":class="permissionPhaseState ? (dataItem.isSelect ? (isDisabled ? dataItem.classname + ' not-checked' : dataItem.classname) : '') : 'not-select'":disabled="isDisabled":value="dataItem.value"@click="handleSetPermission(dataItem)"/></label></div>
</template><!--
==============================================================================
JavaScript:Vue.js
==============================================================================
--><script>
export default {name: 'PermissionCheckbox',props: {isDisabled: {type: Boolean,default: false},permissionItem: {type: Array,default: () => []},permissionPhase: {type: String,default: ''},permissionPhaseState: {type: Boolean,default: false}},data() {return {dataList: [{ permissionName: 'write', isSelect: false, value: 'W', classname: 'focus_W' },{ permissionName: 'read', isSelect: false, value: 'R', classname: 'focus_R' },],}},mounted() {this.dataList.forEach(item => {if(item.permissionName === this.permissionItem[0]) {item.isSelect = true} else {item.isSelect = false}})},watch: {permissionItem(newVal) {this.dataList.forEach(item => {if(item.permissionName === newVal[0]) {item.isSelect = true} else {item.isSelect = false}})}},computed: {permission() {if(this.dataList[0].isSelect) {return this.dataList[0].permissionName} else if(this.dataList[1].isSelect) {return this.dataList[1].permissionName} else {return 'none'}}},methods: {handleSetPermission(dataItem) {this.dataList.forEach(item => {if(item.permissionName === dataItem.permissionName) {item.isSelect = !item.isSelect} else {item.isSelect = false}})if(this.permission !== '') {this.$emit('click-button-permission', this.permission)}}}
}
</script><!--
==============================================================================
CSS3
==============================================================================
--><style scoped>
.checkboxs {display: flex;justify-content: space-evenly;align-items: center;height: 28px;
}.checkbox {cursor: pointer;box-sizing: border-box;width: 20px;height: 20px;line-height: 20px;outline: none;border: 0;border-radius: 4px;background-color: #cad6e8;text-align: center;padding: 0;font-size: 14px;font-weight: 700;color: #fff;
}.focus_W {font-weight: 700;box-sizing: border-box;background-color: #ed7a06;border: 0;color: white;box-shadow: 0px 3px 3px rgba(237, 122, 6, .3);
}.focus_R {font-weight: 700;box-sizing: border-box;background-color: #c0cb22;border: 0;color: white;box-shadow: 0px 3px 3px rgba(178, 188, 49, .3);
}.not-checked {cursor: not-allowed;font-weight: 700;box-sizing: border-box;border: 0;color: white;
}.not-select {cursor: not-allowed;font-weight: 700;box-sizing: border-box;border: 0;color: white;
}
</style>

效果图
在这里插入图片描述
在这里插入图片描述
在这里插入图片描述

http://www.lryc.cn/news/44070.html

相关文章:

  • 让PyTorch训练速度更快,你需要掌握这17种方法
  • LeetCode-309. 最佳买卖股票时机含冷冻期
  • AUTOSAR知识点Com(七):CANSM初认知
  • 递归:斐波那契数列、递归实现指数型枚举、递归实现排列型枚举
  • oracle模糊查询时字段内容包含下划线的解决办法
  • C++:explicit关键字
  • 【C5】bmc wtd,post
  • 200.Spark(七):SparkSQL项目实战
  • 区块链系统:挖矿原理
  • 【博弈】【清华冬令营2018模拟】取石子
  • 嵌入式:BSP的理解
  • Linux主机Tcpdump使用-centos实例
  • 线性DP——AcWing 898. 数字三角形、AcWing 895. 最长上升子序列
  • SpringMVC
  • C++模板基础(二)
  • 什么是linux内核态、用户态?
  • day8—选择题
  • ngx错误日志error_log配置
  • 1.11、自动化
  • 函数的定义与使用及七段数码管绘制
  • 怎么压缩pdf文件大小?pdf文件太大如何压缩?
  • 阿里云Linux服务器登录名ecs-user和root选择问题
  • 【云原生】 初体验阿里云Serverless应用引擎SAE(三),挂载配置文件使应用的配置和运行的镜像解耦
  • Oracle用户密码过期,修改永不过期
  • welearn 视听说1-4
  • 【git】将本地项目同步到远程
  • 10-链表练习-LeetCode82删除排序链表中的重复元素II
  • 贯穿设计模式第五话--接口隔离原则
  • C语言计算机二级/C语言期末考试 刷题(四)
  • JDK8中Stream接口的常用方法