vue封装element ui组件

vue封装element ui组件 —— 以 el-process 标签为例

1、封装

根据 element UI 的进度条 ,将你用到的一些属性都以子组件取参(props)的形式注册,必填或者指定默认值的用格式1,其他的你可以指定参数类型。其他情况请参考[官方文档]。(https://cn.vuejs.org/v2/guide/components-props.html)

<template>
	<el-progress 
	:type="type" 
	:percentage="percentage" 
	:status="status" 
	:width="width"
	:stroke-width="strokeWidth"
	/>
</template>

<script>
	export default {
		// 可以理解为注册绑定参数,并赋默认值
		props: { 
			type: {
				type: String,
				default: "circle"
			},
			percentage: {
				type: Number,
				default: 20 
			},
			colors: {
				type: String,
				default: "circle"
			},
			status: String,
			width: Number,
			strokeWidth:{
				type: Number,
				default: 6
			}
		}
	}
</script>

<style lang="scss" scoped>

</style>

2、使用

1)在需要使用的页面引入该组件,并在 components 中注册;
2)写上你需要放的参数

<template>
	<div style="background-color: #fff;padding: 30px;">
		<!-- 3、使用 -->
		<Process :strokeWidth="15" />
	</div>
</template>

<script>
	import Process from '@/components/Progress/index.vue'// 1、导入
	export default {
		components:{Process},// 2、引入
		methods: {
			test() {}
		}
	}
</script>

<style></style>

在这里插入图片描述

  • 0
    点赞
  • 2
    收藏
    觉得还不错? 一键收藏
  • 0
    评论
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

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

抵扣说明:

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

余额充值