【elementui】颜色选择器

前言

element-ui 2.x中的颜色选择器,预定义模式中最后一个元素无法选中
在这里插入图片描述
原因:颜色编码有误
在这里插入图片描述

修改

右边下拉到最底部,找到红色,放进去即可
在这里插入图片描述

补充组件代码

<template>
  <div class="public-input-color-picker">
    <el-input v-model="value2" :placeholder="placeholder" @input="_change"></el-input>
    <el-color-picker
      v-model="value2"
      :show-alpha="showAlpha"
      :predefine="predefineColors"
      @change="_change"
    ></el-color-picker>
  </div>
</template>
<script>
/**
 * 输入框颜色选择器
 * ps:预定义颜色中,如果颜色不对,将无法选中
 *
 * @showAlpha 是否支持透明度 默认false
 * @predefineColors 预定义颜色
 * @value 默认颜色编码 示例:#ffffff
 * @placeholder 输入框提示文字
 */
export default {
  name: 'public-input-color-picker',
  data() {
    return {
      value2: ''
    }
  },
  props: {
    showAlpha: { type: Boolean, default: false },
    predefineColors: {
      type: Array,
      default: () => {
        return [
          '#ff4500',
          '#ff8c00',
          '#ffd700',
          '#90ee90',
          '#00ced1',
          '#1e90ff',
          '#c71585',
          '#FF0000'
        ]
      }
    },
    value: { type: String, default: '' },
    placeholder: { type: String, default: '请输入颜色编码' }
  },
  components: {},
  computed: {},
  created() {
  },
  onload() { },
  onShow() { },
  watch: {
    value: {
      handler: function (newVal, oldVal) {
        this.value2 = JSON.parse(JSON.stringify(newVal))
      },
      immediate: true,
      deep: true
    }
  },
  mounted() { },
  methods: {
    _change(val) {
      if (val) {
        this.$emit('change', val)
      }
    }
  }
}
</script>
<style lang="less" scoped>
@box-width: 200px;
.public-input-color-picker {
  // display: flex;
  // -webkit-box-align: center;
  // -webkit-align-items: center;
  // align-items: center;
  position: relative;
  width: @box-width;
  .el-input {
    width: @box-width;
  }
  .el-color-picker {
    position: absolute;
    right: 0;
    /deep/ .el-color-picker__trigger {
      border: 0;
    }
  }
}
</style>

组件调用代码

<public-input-color-picker
            :value="form2.labelColor"
            placeholder="请输入标签颜色"
            @change="(val)=>{form2.labelColor=val}"
          />
  • 4
    点赞
  • 8
    收藏
    觉得还不错? 一键收藏
  • 0
    评论

“相关推荐”对你有帮助么?

  • 非常没帮助
  • 没帮助
  • 一般
  • 有帮助
  • 非常有帮助
提交
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值