这里是一个简单的Vue组件,使用Element UI的Icon组件实现一个睁眼睛的图标:

<template>
  <el-icon :class="{'el-icon-circle': !isOpen, 'el-icon-circle-check': isOpen}" @click="toggle"></el-icon>
</template>

<script>
export default {
  data() {
    return {
      isOpen: false
    }
  },
  methods: {
    toggle() {
      this.isOpen = !this.isOpen;
    }
  }
}
</script>

在模板中,我们使用Element UI的Icon组件,并根据isOpen属性的值添加不同的class,实现睁眼睛和闭眼睛的切换。

在脚本中,我们定义了一个isOpen属性,用于判断当前图标的状态。我们还定义了一个toggle方法,用于切换isOpen属性的值。

这个组件可以直接在Vue应用中使用,例如:

<template>
  <div>
    <EyeIcon />
  </div>
</template>

<script>
import EyeIcon from './EyeIcon.vue';

export default {
  components: {
    EyeIcon
  }
}
</script>

在这个例子中,我们把EyeIcon组件导入到父组件中,并在模板中使用它

给我用vue + elementUi一个睁眼睛的图标

原文地址: https://www.cveoy.top/t/topic/efxL 著作权归作者所有。请勿转载和采集!

免费AI点我,无需注册和登录