【区分vue2和vue3下的element UI Tree 树形组件,分别详细介绍属性,事件,方法如何使用,并举例】

在 Vue 2 的 Element UI 和 Vue 3 的 Element Plus 中,Progress 进度条组件在功能和用法上有很多相似之处,但也有一些细微的差别。下面我将分别介绍这两个版本中的 Progress 组件的属性、事件和方法,并给出使用示例。

Vue 2 + Element UI Progress

属性 (Attributes)
  • percentage: 百分比(必填),范围 0-100。
  • type: 进度条类型,可选值为 line(线形)和 circle(圆形)。
  • status: 进度条状态,可选值为 successexceptionwarning,分别表示成功、异常和警告。
  • stroke-width: 进度条的线宽,单位 px。
  • color: 进度条的颜色。
  • show-text: 是否显示进度条文本内容。
  • text-inside: 进度条文本是否内置到进度条内(仅在 type="circle" 时有效)。
  • width: 进度条宽度(仅在 type="line" 时有效),单位可以是 px%
事件 (Events)

Element UI 的 Progress 组件没有暴露特定的事件。但你可以使用原生的 DOM 事件(如 clickmouseover 等)。

方法 (Methods)

Progress 组件没有直接提供方法。

示例
<template>
  <el-progress
    :percentage="50"
    type="circle"
    :color="'#409EFF'"
    :status="'success'"
    :text-inside="true"
  ></el-progress>
  <el-progress
    :percentage="80"
    type="line"
    :stroke-width="20"
    :show-text="false"
  ></el-progress>
</template>

<script>
export default {
  data() {
    return {
      // 这里没有特定的进度条相关数据,因为直接在模板中设置了
    };
  }
};
</script>

Vue 3 + Element Plus Progress

属性 (Attributes)
  • percentage: 百分比(必填),范围 0-100。
  • type: 进度条类型,可选值为 line(线形)和 circle(圆形)。
  • status: 进度条状态,可选值为 successexceptionwarning
  • stroke-width: 进度条的线宽,单位 px。
  • color: 进度条的颜色,可以使用对象来自定义多色进度条。
  • show-text: 是否显示进度条文本内容。
  • text-inside: 进度条文本是否内置到进度条内(仅在 type="circle" 时有效)。
  • gap-degree: 圆形进度条缺口的角度,仅在 type="circle" 时有效。
  • gap-position: 圆形进度条缺口的位置,仅在 type="circle" 时有效,可选值为 topbottomleftright
  • width: 进度条宽度(仅在 type="line" 时有效),单位可以是 px%
事件 (Events)

与 Element UI 类似,Element Plus 的 Progress 组件也没有暴露特定的事件。

方法 (Methods)

Progress 组件没有直接提供方法。

示例
<template>
  <el-progress
    :percentage="50"
    type="circle"
    :color="'#409EFF'"
    :status="'success'"
    :text-inside="true"
    :gap-degree="75"
    :gap-position="'top'"
  ></el-progress>
  <el-progress
    :percentage="80"
    type="line"
    :stroke-width="20"
    :width="200"
    :show-text="false"
  ></el-progress>
</template>

<script setup>
// 在这个版本的 Vue 中,使用 `<script setup>` 语法糖,因此没有显式的 data、methods 等
</script>

差异

  • Element Plus 在 Progress 组件中增加了 gap-degreegap-position 属性,用于圆形进度条的缺口设置。
  • Element Pluscolor 属性支持使用对象来自定义多色进度条,这在 Element UI 中是不可用的。
  • Vue 3<script setup> 语法糖
  • 11
    点赞
  • 7
    收藏
    觉得还不错? 一键收藏
  • 打赏
    打赏
  • 0
    评论
Vue2 封装 Element UI Tree 组件的步骤如下: 1. 安装 Element UI ```bash npm install element-ui --save ``` 2. 在 main.js 中引入 Element UI ```js import Vue from 'vue' import ElementUI from 'element-ui' import 'element-ui/lib/theme-chalk/index.css' Vue.use(ElementUI) ``` 3. 创建 Tree.vue 组件 ```vue <template> <el-tree :data="data" :props="defaultProps" @node-click="handleNodeClick"> </el-tree> </template> <script> export default { name: 'Tree', props: { data: { type: Array, default: () => [] }, defaultProps: { type: Object, default: () => ({ children: 'children', label: 'label' }) } }, methods: { handleNodeClick(node) { this.$emit('node-click', node) } } } </script> ``` 4. 在需要使用 Tree组件中引入 Tree 组件 ```js import Tree from './Tree.vue' export default { name: 'MyComponent', components: { Tree }, data() { return { treeData: [ { label: '一级 1', children: [ { label: '二级 1-1', children: [ { label: '三级 1-1-1' }, { label: '三级 1-1-2' } ] }, { label: '二级 1-2', children: [ { label: '三级 1-2-1' }, { label: '三级 1-2-2' } ] } ] }, { label: '一级 2', children: [ { label: '二级 2-1', children: [ { label: '三级 2-1-1' }, { label: '三级 2-1-2' } ] }, { label: '二级 2-2', children: [ { label: '三级 2-2-1' }, { label: '三级 2-2-2' } ] } ] } ], defaultProps: { children: 'children', label: 'label' } } }, methods: { handleNodeClick(node) { console.log(node) } } } ``` 5. 在组件模板中使用 Tree 组件 ```vue <template> <div> <tree :data="treeData" :default-props="defaultProps" @node-click="handleNodeClick"> </tree> </div> </template> ```

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

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

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包

打赏作者

加仑小铁

你的鼓励将是我创作的最大动力

¥1 ¥2 ¥4 ¥6 ¥10 ¥20
扫码支付:¥1
获取中
扫码支付

您的余额不足,请更换扫码支付或充值

打赏作者

实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

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

余额充值