arco disign 封装数值范围组件

实现效果:
在这里插入图片描述
环境:vue3 + arco disign vue + a_input_number

实现代码: NumRange.vue

<template>
<span>
	<a-input-number
	v-model="minValue"
	style="width: 45%"
	v-bind="options"
	@input="minInput"/>
	<span
	:style="{
	display: 'inline-block',
	width: '24px',
	textAlign: 'center',
	}"
	>-</span
	<a-input-number
	v-model="maxValue"
	style="width: 45%"
	v-bind="options'
	@input="maxInput"/>
</span>
<script lang="ts" setup>
	import { reactive, watch, ref } from 'vue';
	const minValue = ref<any>(undefined);
	const maxValue = ref<any>(undefined);
	const props = defineProps({
		modelValue: {
			type: Array,
			default() {
				return [];
			},
		},
		options:{
			type: Object,
			default(){
				return {};
			};
		}
	});
	const emit = defineEmits(['update:modelValue']);
	watch(() => props.modelValue,(newVal, oldVal) => {
			minValue.value = newVal[0] ? newVal[0] : undefined;
			maxValue.value = newVal[1] ? newVal[1] : undefined;
	    },
		{ deep: true, immediate: true }
	);
	const change = () => {
		let result = [];
		if (minvalue.value !== undefined || maxValue.value !== undefined) {
			result = [minValue.value, maxValue.value];
		}
		emit('update:modelValue', result);
	};
	const minInput = (value) => {
		minValue.value = value;
	    change();
	};
	const maxInput = (value) => {
		maxValue.value = value;
		change();
	};
</script>

调用组件

<template>
	<NumRange v-model:modelValue = "rangeValue":option="{min:10, max:20}"></NumRange>
</tamplate>
<script lang="ts" setup>
    import { reactive, watch, ref } from 'vue';
	import NumRange from '@/views/xxx/NumRange.vue'
    const rangeValue = ref([3, 4]);
</script>

NumRange组件只对值进行双向绑定, option:参数可参考官网a-input-number的属性,
可再此基础上对外扩展事件,方法,参数.
父组件赋值默认值为空数组, 或带值的数组

  • 5
    点赞
  • 7
    收藏
    觉得还不错? 一键收藏
  • 2
    评论

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

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

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

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

抵扣说明:

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

余额充值