網(wǎng)站首頁(yè) Vue 正文
效果
?封裝的組件
<template> <el-form-item :label="label"> <el-checkbox :indeterminate="isIndeterminateBool" v-model="checkAll" @change="handleCheckAllChange">全選 </el-checkbox> <el-checkbox-group v-model="checkList" @change="handleCheckedCitiesChange"> <el-checkbox :label="key" v-for="(item,key) in this.channelList" :key="key">{{ item }} </el-checkbox> </el-checkbox-group> </el-form-item> </template> <script> import {channelList} from "@/utils/app-channel"; export default { name: "Index", data() { return { //渠道列表 全部渠道 channelList: channelList, // checkbox 的不確定狀態(tài),一般用于實(shí)現(xiàn)全選的效果 isIndeterminateBool: true, //全選默認(rèn)不勾選 checkAll: false, data: this.checkList, } }, computed: { checkList: { get: function () { return (this.item[this.formDBName] || '').split("|").filter(str => (!!str)); }, set: function (newValue) { this.item[this.formDBName] = newValue.join("|"); } } }, props: { //表單名稱 label: { type: String, required: true }, //當(dāng)前選中項(xiàng) item: { type: Object, required: true }, formDBName: { type: String, required: true } }, methods: { getArrayCheckList() { return (this.item[this.formDBName] || '').split("|").filter(str => (!!str)); }, //將數(shù)據(jù)返回給父組件 setChooseData(data) { this.$emit("choose-data", this.formDBName, data) }, //value 代表選中還是未選中 ture false兩個(gè)取值 handleCheckAllChange(value) { const chooseChannel = Object.keys(this.channelList) this.checkList = value ? chooseChannel : []; this.isIndeterminateBool = false; this.checkAll = value; const formData = this.checkList.join("|"); this.setChooseData(formData) }, //選中后計(jì)算全選 handleCheckedCitiesChange(value) { const chooseChannel = Object.keys(this.channelList); let checkedCount = value.length; this.checkAll = checkedCount === chooseChannel.length; this.isIndeterminateBool = checkedCount > 0 && checkedCount < chooseChannel.length; const formData = value.join("|"); this.setChooseData(formData) }, }, mounted() { // .split("|").filter(str => (!!str && typeof (str) == 'string')) } } </script> <style scoped> </style>
渠道列表?
// export const channelList = { "anguo": "安果", "baidu": "百度", "huawei": "華為", "samsung": "三星", "oppo": "OPPO", "sanliuling": "360", "meizu": "魅族", "vivo": "VIVO", "wandoujia": "豌豆莢", "xiaomi": "小米", "yyb": "應(yīng)用寶", "yyh": "應(yīng)用匯", };
父組件使用
<el-card shadow="hover"> <multiple-choice :item="item" label="渠道/廣告開關(guān)" form-d-b-name="channel" @choose-data="onCheckResult"></multiple-choice> </el-card>
item[channle]
是存入字符串的以|分割的數(shù)據(jù)
比如
baidu|anguo|yyb
這樣
onCheckResult
onCheckResult(dbName, res) { this.item[dbName] = res; }
總結(jié)
原文鏈接:https://blog.csdn.net/mp624183768/article/details/122802281
相關(guān)推薦
- 2021-12-06 GO語(yǔ)言臨界資源安全問(wèn)題的深入理解_Golang
- 2022-12-07 C++?Boost?Array與Unordered使用介紹_C 語(yǔ)言
- 2022-04-16 C++實(shí)現(xiàn)二維圖形的打印_C 語(yǔ)言
- 2022-09-25 FFmpeg源碼分析:圖像常用操作
- 2023-01-05 詳解C++中四種類型的轉(zhuǎn)換_C 語(yǔ)言
- 2022-03-28 .Net?Core依賴注入IOC和DI介紹_實(shí)用技巧
- 2022-09-21 Python?Ast抽象語(yǔ)法樹的介紹及應(yīng)用詳解_python
- 2022-05-19 PyTorch中的torch.cat簡(jiǎn)單介紹_python
- 最近更新
-
- window11 系統(tǒng)安裝 yarn
- 超詳細(xì)win安裝深度學(xué)習(xí)環(huán)境2025年最新版(
- Linux 中運(yùn)行的top命令 怎么退出?
- MySQL 中decimal 的用法? 存儲(chǔ)小
- get 、set 、toString 方法的使
- @Resource和 @Autowired注解
- Java基礎(chǔ)操作-- 運(yùn)算符,流程控制 Flo
- 1. Int 和Integer 的區(qū)別,Jav
- spring @retryable不生效的一種
- Spring Security之認(rèn)證信息的處理
- Spring Security之認(rèn)證過(guò)濾器
- Spring Security概述快速入門
- Spring Security之配置體系
- 【SpringBoot】SpringCache
- Spring Security之基于方法配置權(quán)
- redisson分布式鎖中waittime的設(shè)
- maven:解決release錯(cuò)誤:Artif
- restTemplate使用總結(jié)
- Spring Security之安全異常處理
- MybatisPlus優(yōu)雅實(shí)現(xiàn)加密?
- Spring ioc容器與Bean的生命周期。
- 【探索SpringCloud】服務(wù)發(fā)現(xiàn)-Nac
- Spring Security之基于HttpR
- Redis 底層數(shù)據(jù)結(jié)構(gòu)-簡(jiǎn)單動(dòng)態(tài)字符串(SD
- arthas操作spring被代理目標(biāo)對(duì)象命令
- Spring中的單例模式應(yīng)用詳解
- 聊聊消息隊(duì)列,發(fā)送消息的4種方式
- bootspring第三方資源配置管理
- GIT同步修改后的遠(yuǎn)程分支