# el-link-dict组件

仅用于标记,方便使用标记数据来源于字典时使用。如某某某状态对应某某某type的标记。 支持el-link所有属性,事件及slot。 调用getRef() 返回el-link实例

type属性来选择tag的类型,type没传时默认primary类型,也可以通过color属性来自定义背景色。

<template>
  <div class="el-link-dict" ref="container">
    <div class="title">基础用法</div>
    <div class="normal-tag">
      <el-link-dict dictType="PERSON_TYPE" :value="value1"></el-link-dict>
      <el-link-dict type="success" dictType="PERSON_TYPE" :value="value2"></el-link-dict>
      <el-link-dict dictType="PERSON_TYPE" :value="value3"></el-link-dict>
      <el-link-dict type="warning" dictType="PERSON_TYPE" :value="value4"></el-link-dict>
      <el-link-dict  dictType="PERSON_TYPE" :value="value5"></el-link-dict>
    </div>

    <div class="title">使用函数</div>
    <div class="function-tag">
      <el-link-dict :judgeTypeFun="judgeTypeFun" dictType="PERSON_TYPE" :value="value1"></el-link-dict>
      <el-link-dict :judgeTypeFun="judgeTypeFun" dictType="PERSON_TYPE" :value="value2"></el-link-dict>
      <el-link-dict :judgeTypeFun="judgeTypeFun" dictType="PERSON_TYPE" :value="value3"></el-link-dict>
      <el-link-dict :judgeTypeFun="judgeTypeFun" dictType="PERSON_TYPE" :value="value4"></el-link-dict>
      <el-link-dict :judgeTypeFun="judgeTypeFun" dictType="PERSON_TYPE" :value="value5"></el-link-dict>
    </div>
  </div>
</template>

<script>
export default {
  data() {
    return {
      value1: "001",
      value2: "002",
      value3: "003",
      value4: "004",
      value5: "005"
    }
  },
  mounted() {},
  methods: {
    //val 为字典数据值
    judgeTypeFun(val) {
      const typeObj = {
        "001": "danger",
        "002": "warning",
        "003": "info",
        "004": "success",
        "005": "primary"
      }
      return typeObj[val]
    }
  }
}
</script>

<style lang="less" scoped>
.el-link + .el-link{
  margin-left: 10px;
}
</style>
显示代码
参数 说明 类型 可选值 默认值
dictType 必传,传递字典类型 String
value 必传,数据值 [String, Number]
type 选传,默认 primary judgeTypeFun优先级更高 String primary,success,info,warning,danger primary
judgeTypeFun 选传,不传则获取type配置,所以未返回值时默认primary Function type的类型

注意:如此组件满足不了需求,可直接使用el-link原生组件,查阅原生组件文档 (opens new window)

爆米花小布微信公众号

上次更新: 7/11/2024, 4:01:24 PM