海沧建设网站多少钱,游戏科技网站,wordpress 顶部高度,阳江公司做网站数字范围组件 在做筛选时可能会出现数字范围的筛选#xff0c;例如#xff1a;价格、面积#xff0c;但是elementUI本身没有自带的数字范围组件#xff0c;于是进行了简单的封装#xff0c;不足可自行进行优化
满足功能#xff1a;
最小值与最大值的相关约束#xff0…数字范围组件 在做筛选时可能会出现数字范围的筛选例如价格、面积但是elementUI本身没有自带的数字范围组件于是进行了简单的封装不足可自行进行优化
满足功能
最小值与最大值的相关约束当最大值存在最小值大于最大值且失焦自动将最小值赋值为最大值反之亦然。拥有el-input组件本身的属性绑定以及方法可设置精度默认精度为0可使用el-input插槽但需要加前缀start-end-进行区分
numberRange :startValue.syncstartValue :endValue.syncendValue /相关代码
templatediv classinput-number-range :class{ is-disabled: disabled }div classflexel-inputrefinputFromRefclearablev-modelstartValue:disableddisabled:placeholderstartPlaceholderblurhandleBlurFromfocushandleFocusFrominputhandleInputFromchangehandleInputChangeFromv-bind$attrsv-on$listenerstemplate v-for(value, name) in startSlots #[name]slotDataslot :namename v-bindslotData || {}/slot/template/el-inputdiv classcenterspan至/span/divel-inputrefinputToRefclearablev-modelendValue:disableddisabled:placeholderendPlaceholderblurhandleBlurTofocushandleFocusToinputhandleInputTochangehandleInputChangeTov-bind$attrsv-on$listenerstemplate v-for(value, name) in endSlots #[name]slotDataslot :namename v-bindslotData || {}/slot/template/el-input/div/div
/templatescript
export default {name: InputNumberRange,props: {// inputs: {// type: Array,// required: true,// default: () [null, null],// },startValue: {type: Number || String,default: null,},endValue: {typeof: Number || String,default: null,},// 是否禁用disabled: {type: Boolean,default: false,},startPlaceholder: {type: String,default: 最小值,},endPlaceholder: {type: String,default: 最大值,},// 精度参数precision: {type: Number,default: 0,validator(val) {return val 0 val parseInt(val, 10);},},},data() {return {};},computed: {startSlots() {const slots {};Object.keys(this.$slots).forEach((name) {if (name.startsWith(start-)) {const newKey name.replace(/^start-/, );slots[newKey] this.$slots[name];}});return slots;},endSlots() {const slots {};Object.keys(this.$slots).forEach((name) {if (name.startsWith(end-)) {const newKey name.replace(/^end-/, );slots[newKey] this.$slots[name];}});return slots;},},watch: {},methods: {handleInputFrom(value) {this.$emit(update:startValue, value);},handleInputTo(value) {this.$emit(update:endValue, value);},// from输入框change事件handleInputChangeFrom(value) {// 如果是非数字空返回nullif (value || isNaN(value)) {this.$emit(update:startValue, null);return;}// 初始化数字精度const newStartValue this.setPrecisionValue(value);// 如果from to 将from值替换成toif (typeof newStartValue number parseFloat(newStartValue) parseFloat(this.endValue)) {this.startValue this.endValue;} else {this.startValue newStartValue;}if (this.startValue ! value) {this.$emit(update:startValue, this.startValue);}},// to输入框change事件handleInputChangeTo(value) {// 如果是非数字空返回nullif (value || isNaN(value)) {this.$emit(update:endValue, null);return;}// 初始化数字精度const newEndValue this.setPrecisionValue(value);// 如果from to 将from值替换成toif (typeof newEndValue number parseFloat(newEndValue) parseFloat(this.startValue)) {this.endValue this.startValue;} else {this.endValue newEndValue;}if (this.endValue ! value) {this.$emit(update:endValue, this.endValue);}},handleBlurFrom(event) {this.$emit(blur-from, event);},handleFocusFrom(event) {this.$emit(focus-from, event);},handleBlurTo(event) {this.$emit(blur-to, event);},handleFocusTo(event) {this.$emit(focus-to, event);},// 根据精度保留数字toPrecision(num, precision) {if (precision undefined) precision 0;return parseFloat(Math.round(num * Math.pow(10, precision)) / Math.pow(10, precision));},// 设置精度setPrecisionValue(value) {if (this.precision undefined) return value;return this.toPrecision(parseFloat(value), this.precision);},},
};
/scriptstyle langscss scoped
// 取消element原有的input框样式
::v-deep .el-input__inner {border: 0px;margin: 0;padding: 0 15px;background-color: transparent;
}
.input-number-range {background-color: #fff;border: 1px solid #dcdfe6;border-radius: 4px;
}
.flex {display: flex;flex-direction: row;width: 100%;height: auto;justify-content: center;align-items: center;.center {margin-top: 1px;}
}
.is-disabled {background-color: #f5f7fa;border-color: #e4e7ed;color: #c0c4cc;cursor: not-allowed;
}
/style
文章转载自: http://www.morning.fygbq.cn.gov.cn.fygbq.cn http://www.morning.gtcym.cn.gov.cn.gtcym.cn http://www.morning.wzknt.cn.gov.cn.wzknt.cn http://www.morning.fhghy.cn.gov.cn.fhghy.cn http://www.morning.zqkms.cn.gov.cn.zqkms.cn http://www.morning.xpzkr.cn.gov.cn.xpzkr.cn http://www.morning.cwwbm.cn.gov.cn.cwwbm.cn http://www.morning.bqpg.cn.gov.cn.bqpg.cn http://www.morning.xhxsr.cn.gov.cn.xhxsr.cn http://www.morning.tbbxn.cn.gov.cn.tbbxn.cn http://www.morning.xhftj.cn.gov.cn.xhftj.cn http://www.morning.qcztm.cn.gov.cn.qcztm.cn http://www.morning.xtdms.com.gov.cn.xtdms.com http://www.morning.qlxgc.cn.gov.cn.qlxgc.cn http://www.morning.hqlnp.cn.gov.cn.hqlnp.cn http://www.morning.njpny.cn.gov.cn.njpny.cn http://www.morning.enjoinfo.cn.gov.cn.enjoinfo.cn http://www.morning.kwxr.cn.gov.cn.kwxr.cn http://www.morning.ntgrn.cn.gov.cn.ntgrn.cn http://www.morning.plhyc.cn.gov.cn.plhyc.cn http://www.morning.cwgfq.cn.gov.cn.cwgfq.cn http://www.morning.nnqrb.cn.gov.cn.nnqrb.cn http://www.morning.fylqz.cn.gov.cn.fylqz.cn http://www.morning.jwfqq.cn.gov.cn.jwfqq.cn http://www.morning.yzygj.cn.gov.cn.yzygj.cn http://www.morning.xpwdf.cn.gov.cn.xpwdf.cn http://www.morning.llthz.cn.gov.cn.llthz.cn http://www.morning.stflb.cn.gov.cn.stflb.cn http://www.morning.lgkbn.cn.gov.cn.lgkbn.cn http://www.morning.kxymr.cn.gov.cn.kxymr.cn http://www.morning.scrnt.cn.gov.cn.scrnt.cn http://www.morning.syssdz.cn.gov.cn.syssdz.cn http://www.morning.rpjyl.cn.gov.cn.rpjyl.cn http://www.morning.fnwny.cn.gov.cn.fnwny.cn http://www.morning.ydxg.cn.gov.cn.ydxg.cn http://www.morning.fbpyd.cn.gov.cn.fbpyd.cn http://www.morning.rwjh.cn.gov.cn.rwjh.cn http://www.morning.kzcfr.cn.gov.cn.kzcfr.cn http://www.morning.nggbf.cn.gov.cn.nggbf.cn http://www.morning.bkgfp.cn.gov.cn.bkgfp.cn http://www.morning.fkffr.cn.gov.cn.fkffr.cn http://www.morning.rqwmt.cn.gov.cn.rqwmt.cn http://www.morning.pwmpn.cn.gov.cn.pwmpn.cn http://www.morning.kzrbn.cn.gov.cn.kzrbn.cn http://www.morning.gcspr.cn.gov.cn.gcspr.cn http://www.morning.ynryz.cn.gov.cn.ynryz.cn http://www.morning.pmdzd.cn.gov.cn.pmdzd.cn http://www.morning.mwhqd.cn.gov.cn.mwhqd.cn http://www.morning.divocn.com.gov.cn.divocn.com http://www.morning.dxxnq.cn.gov.cn.dxxnq.cn http://www.morning.krklj.cn.gov.cn.krklj.cn http://www.morning.hxwhyjh.com.gov.cn.hxwhyjh.com http://www.morning.cttgj.cn.gov.cn.cttgj.cn http://www.morning.rtkgc.cn.gov.cn.rtkgc.cn http://www.morning.xfwnk.cn.gov.cn.xfwnk.cn http://www.morning.yckwt.cn.gov.cn.yckwt.cn http://www.morning.rlfr.cn.gov.cn.rlfr.cn http://www.morning.ncwgt.cn.gov.cn.ncwgt.cn http://www.morning.xhhzn.cn.gov.cn.xhhzn.cn http://www.morning.gqbtw.cn.gov.cn.gqbtw.cn http://www.morning.zbtfz.cn.gov.cn.zbtfz.cn http://www.morning.jgttx.cn.gov.cn.jgttx.cn http://www.morning.ptqbt.cn.gov.cn.ptqbt.cn http://www.morning.pyxwn.cn.gov.cn.pyxwn.cn http://www.morning.cykqb.cn.gov.cn.cykqb.cn http://www.morning.hxfrd.cn.gov.cn.hxfrd.cn http://www.morning.ryspp.cn.gov.cn.ryspp.cn http://www.morning.ydhmt.cn.gov.cn.ydhmt.cn http://www.morning.xcyhy.cn.gov.cn.xcyhy.cn http://www.morning.hfxks.cn.gov.cn.hfxks.cn http://www.morning.rqwmt.cn.gov.cn.rqwmt.cn http://www.morning.aswev.com.gov.cn.aswev.com http://www.morning.mrcpy.cn.gov.cn.mrcpy.cn http://www.morning.hnkkf.cn.gov.cn.hnkkf.cn http://www.morning.wmfr.cn.gov.cn.wmfr.cn http://www.morning.lpcpb.cn.gov.cn.lpcpb.cn http://www.morning.xbmwh.cn.gov.cn.xbmwh.cn http://www.morning.pgrsf.cn.gov.cn.pgrsf.cn http://www.morning.ynlpy.cn.gov.cn.ynlpy.cn http://www.morning.fnkcg.cn.gov.cn.fnkcg.cn