你有二次封装过ElementUI组件吗?
发布于 2021-01-11 17:02:27
关注者
0
被浏览
1611
6 个回答
-
有啊! 类似于分页, 表格, 毕竟每个项目的这些东西, 比如pageSize, size, 这些在每个项目基本都是统一的,
设置起来会有四五个参数prop
是固定的, 我不可能每次使用的时候都设置一次 -
-
-
你怎么封装的?
其实是简单的做了下处理,大概如下
<template> <el-input placeholder="价格" v-model="current" :disabled="disabled" :maxlength="8" @change="change" ></el-input> </template> <script> export default { props: { value: Number, disabled: Boolean }, data() { return { current: "" }; }, watch: { value(val) { if (val > 0) { this.current = (val / 100).toFixed(2); } else { this.current = ""; } } }, created() { if (this.value > 0) { this.current = (this.value / 100).toFixed(2); } else { this.current = ""; } }, methods: { change() { let value = this.current * 100 || 0; this.current = (value / 100).toFixed(2); this.$emit("input", value.toFixed(0) * 1); } } }; </script>
-
嗯~ 这样有点问题,比如我输入 1 输入框的值就变成了 1.00 但是我想输入 10 ,导致我输入1之后,立马变成了 1.00 加一个函数防抖,感觉会好点
😄 ```javascript fnChnageValue() { if (this.timer) { clearTimeout(this.timer) } this.timer = setTimeout(() => { let value = this.current * 100 || 0 this.current = (value / 100).toFixed(2) this.$emit('input', value.toFixed(0) * 1) }, 1000) } ```