欢迎光临韵绾网
详情描述

方法一:使用CSS类绑定(推荐)

<template>
  <div class="checkbox-container">
    <el-checkbox-group v-model="checkedItems">
      <el-checkbox 
        v-for="item in items" 
        :key="item.id" 
        :label="item.id"
        :class="{ 'checked-item': isChecked(item.id) }"
        @change="handleCheckboxChange"
      >
        <span :class="{ 'strikethrough': isChecked(item.id) }">
          {{ item.name }}
        </span>
      </el-checkbox>
    </el-checkbox-group>
  </div>
</template>

<script>
export default {
  data() {
    return {
      items: [
        { id: 1, name: '选项一' },
        { id: 2, name: '选项二' },
        { id: 3, name: '选项三' },
        { id: 4, name: '选项四' }
      ],
      checkedItems: [2, 4] // 默认选中项
    }
  },
  methods: {
    isChecked(id) {
      return this.checkedItems.includes(id)
    },
    handleCheckboxChange() {
      console.log('选中项:', this.checkedItems)
    }
  }
}
</script>

<style scoped>
/* 删除线样式 */
.strikethrough {
  text-decoration: line-through;
  color: #999;
  opacity: 0.7;
}

/* 可选:调整整个复选框的样式 */
.checked-item {
  /deep/ .el-checkbox__input {
    opacity: 0.7;
  }
}

.checkbox-container {
  padding: 20px;
}
</style>

方法二:使用自定义渲染(更灵活)

<template>
  <div class="checkbox-container">
    <div 
      v-for="item in items" 
      :key="item.id" 
      class="custom-checkbox-item"
      @click="toggleItem(item.id)"
    >
      <div class="checkbox-wrapper">
        <!-- 自定义复选框 -->
        <div class="custom-checkbox" :class="{ 'checked': isChecked(item.id) }">
          <i v-if="isChecked(item.id)" class="el-icon-check"></i>
        </div>

        <!-- 文本内容 -->
        <span class="checkbox-label" :class="{ 'strikethrough': isChecked(item.id) }">
          {{ item.name }}
        </span>
      </div>
    </div>
  </div>
</template>

<script>
export default {
  data() {
    return {
      items: [
        { id: 1, name: '购买牛奶' },
        { id: 2, name: '完成项目报告' },
        { id: 3, name: '健身房锻炼' },
        { id: 4, name: '阅读书籍' }
      ],
      checkedItems: [2]
    }
  },
  methods: {
    isChecked(id) {
      return this.checkedItems.includes(id)
    },
    toggleItem(id) {
      const index = this.checkedItems.indexOf(id)
      if (index === -1) {
        this.checkedItems.push(id)
      } else {
        this.checkedItems.splice(index, 1)
      }
    }
  }
}
</script>

<style scoped>
.checkbox-container {
  padding: 20px;
}

.custom-checkbox-item {
  margin-bottom: 12px;
  cursor: pointer;
}

.checkbox-wrapper {
  display: flex;
  align-items: center;
  gap: 10px;
}

.custom-checkbox {
  width: 18px;
  height: 18px;
  border: 2px solid #dcdfe6;
  border-radius: 4px;
  display: flex;
  align-items: center;
  justify-content: center;
  transition: all 0.2s;
}

.custom-checkbox.checked {
  background-color: #409eff;
  border-color: #409eff;
}

.custom-checkbox.checked i {
  color: white;
  font-size: 12px;
  font-weight: bold;
}

.checkbox-label {
  font-size: 14px;
  color: #606266;
  transition: all 0.3s;
}

/* 删除线效果 */
.strikethrough {
  text-decoration: line-through;
  color: #c0c4cc !important;
  opacity: 0.7;
}

/* 悬停效果 */
.custom-checkbox-item:hover .custom-checkbox {
  border-color: #409eff;
}

.custom-checkbox-item:hover .checkbox-label:not(.strikethrough) {
  color: #409eff;
}
</style>

方法三:使用Element UI的Table组件(适合列表)

<template>
  <div class="table-container">
    <el-table
      :data="items"
      style="width: 100%"
    >
      <el-table-column width="50">
        <template #default="{ row }">
          <el-checkbox 
            v-model="row.checked" 
            @change="handleRowCheck(row)"
          />
        </template>
      </el-table-column>

      <el-table-column label="任务名称">
        <template #default="{ row }">
          <span :class="{ 'strikethrough': row.checked }">
            {{ row.name }}
          </span>
        </template>
      </el-table-column>

      <el-table-column label="状态" width="120">
        <template #default="{ row }">
          <el-tag 
            :type="row.checked ? 'info' : 'primary'" 
            size="small"
          >
            {{ row.checked ? '已完成' : '待完成' }}
          </el-tag>
        </template>
      </el-table-column>
    </el-table>
  </div>
</template>

<script>
export default {
  data() {
    return {
      items: [
        { id: 1, name: '设计原型图', checked: true },
        { id: 2, name: '编写组件文档', checked: false },
        { id: 3, name: '单元测试', checked: true },
        { id: 4, name: '代码审查', checked: false }
      ]
    }
  },
  methods: {
    handleRowCheck(row) {
      console.log(`${row.name}: ${row.checked ? '已完成' : '未完成'}`)
    }
  }
}
</script>

<style scoped>
.table-container {
  padding: 20px;
}

.strikethrough {
  text-decoration: line-through;
  color: #909399;
}

/deep/ .el-table .cell {
  transition: all 0.3s;
}
</style>

增强的删除线效果样式(可选)

/* 更丰富的删除线效果 */
.strikethrough {
  /* 基础删除线 */
  text-decoration: line-through;

  /* 渐变删除线 */
  background: linear-gradient(transparent 40%, #ff6b6b 40%, #ff6b6b 60%, transparent 60%);
  background-size: 100% 100%;
  background-repeat: no-repeat;

  /* 文字样式 */
  color: #a0a0a0 !important;
  opacity: 0.7;
  text-shadow: none;

  /* 动画效果 */
  transition: all 0.4s cubic-bezier(0.4, 0, 0.2, 1);
}

/* 悬停时恢复效果 */
.strikethrough:hover {
  opacity: 1;
  color: #606266 !important;
  text-decoration: none;
  background: none;
}

/* 闪烁动画(选中时) */
@keyframes strike {
  0% { width: 0; }
  100% { width: 100%; }
}

.animate-strike {
  position: relative;
  display: inline-block;
}

.animate-strike::after {
  content: '';
  position: absolute;
  top: 50%;
  left: 0;
  width: 100%;
  height: 2px;
  background: #ff6b6b;
  transform: translateY(-50%);
  animation: strike 0.3s ease-out forwards;
}

主要特点说明:

方法一:最简单,直接使用Element UI的Checkbox组件,通过类绑定实现 方法二:完全自定义,提供了最大的灵活性 方法三:适合在表格中使用,结合Element UI的Table组件 动画效果:可以添加过渡动画增强用户体验

选择哪种方式取决于具体需求:

  • 简单场景用方法一
  • 需要完全控制样式用方法二
  • 表格形式展示用方法三
相关帖子
在2026年,农民工在与用人单位签订合同时应注意哪些薪资条款?
在2026年,农民工在与用人单位签订合同时应注意哪些薪资条款?
父母的住房公积金是否可以用于支持子女购买首套房?
父母的住房公积金是否可以用于支持子女购买首套房?
消费者如何自行初步辨别并避免饮用假冒伪劣的酒精饮料?
消费者如何自行初步辨别并避免饮用假冒伪劣的酒精饮料?
灵活就业人员跨省流动职工医保参保与待遇衔接指南
灵活就业人员跨省流动职工医保参保与待遇衔接指南
阳江市高企申报代办|装修公司注册,无需法人到场,专业代办
阳江市高企申报代办|装修公司注册,无需法人到场,专业代办
梧州市商标注册-工商注册服务,无需法人到场,全程代办
梧州市商标注册-工商注册服务,无需法人到场,全程代办
农民工参加职业技能培训,其培训期间的工资支付是否有保障?
农民工参加职业技能培训,其培训期间的工资支付是否有保障?
洛阳市公司减资变更-公司注册服务电话,欢迎电话咨询
洛阳市公司减资变更-公司注册服务电话,欢迎电话咨询
哈尔滨市网站建设推广服务@app开发,价格透明
哈尔滨市网站建设推广服务@app开发,价格透明
迪庆ICP经营许可证代办|个体工商户注册,专业代办,不成功不收费!
迪庆ICP经营许可证代办|个体工商户注册,专业代办,不成功不收费!
长期佩戴防蓝光眼镜会对眼睛产生依赖性或其他副作用吗?
长期佩戴防蓝光眼镜会对眼睛产生依赖性或其他副作用吗?
面对频繁的极端高温天气,普通人居家和工作中有哪些科学的避暑降温策略?
面对频繁的极端高温天气,普通人居家和工作中有哪些科学的避暑降温策略?
晋城市资质代办公司-中小微企业注册,无需本人到场,全程代办
晋城市资质代办公司-中小微企业注册,无需本人到场,全程代办
美容美白化妆品都是吹嘘的吗?正确的美白方式是什么
美容美白化妆品都是吹嘘的吗?正确的美白方式是什么
2026年公园露营预约规则出新,对帐篷尺寸和搭建区域有哪些新要求?
2026年公园露营预约规则出新,对帐篷尺寸和搭建区域有哪些新要求?
金昌市公司注册资本减资-企业注册代办,本地代办公司,价格合理
金昌市公司注册资本减资-企业注册代办,本地代办公司,价格合理
社保缴费基数的高低,会直接影响到未来养老金的具体数额吗?
社保缴费基数的高低,会直接影响到未来养老金的具体数额吗?
榆林市公司经营范围变更代办电话-广告公司注册,无需法人到场,专业代办
榆林市公司经营范围变更代办电话-广告公司注册,无需法人到场,专业代办
如何识别并应对以“隐孕”为借口的职场霸凌或不合理工作安排?
如何识别并应对以“隐孕”为借口的职场霸凌或不合理工作安排?
吕梁市网站开发建设@购物网站开发,优秀开发团队
吕梁市网站开发建设@购物网站开发,优秀开发团队