element Link源码

<template>
  <a
    :class="[
      'el-link',
      type ? `el-link--${type}` : '',
      disabled && 'is-disabled',
      underline && !disabled && 'is-underline'
    ]"
    :href="href"
    v-bind="$attrs"
    @click="handleClick"
  >

    <el-icon :class="icon" v-if="icon"></el-icon>

    <span v-if="$slots.default" class="el-link--inner">
      <slot></slot>
    </span>

    <template v-if="$slots.icon"><slot v-if="$slots.icon" name="icon"></slot></template>
  </a>
</template>

<script>

export default {
  name: 'ElLink',

  props: {
    // type    类型    string    primary / success / warning / danger / info    default
    type: {
      type: String,
      default: 'default'
    },
    // underline    是否下划线    boolean    —    true
    underline: {
      type: Boolean,
      default: true
    },
    // disabled    是否禁用状态    boolean    —    false
    disabled: Boolean,
    // href    原生 href 属性    
    href: String,
    // icon    图标类名
    icon: String
  },

  methods: {
    handleClick(event) {
      if (!this.disabled) {
        if (!this.href) {
          this.$emit('click', event);
        }
      }
    }
  }
};
</script>

 

posted on 2019-05-31 13:48  心痛随缘  阅读(265)  评论(0编辑  收藏  举报