Vue Input输入框两侧加减框内数字组件
NumberBox组件内容:
<template>
<div class="number-box" :class="{'box-disable': isDisabled}">
<!-- 此处为“减号”标志的图片 -->
<img class="btn-number" src="./reduce.png" @click="onReduce" />
<div class="number-container">
<Input v-model="strVal" @on-enter="onEnter" :disabled="isDisabled" @on-blur="onBlur" placeholeder="请输入范围" />
<div class="unit" v-text="米" />
</div>
<img class="btn-number" src="./recrease.png" @click="onIncrease" />
</div>
</template> <script>
export default {
props: {
isDisabled: {
type: Boolean,
default: false
},
curVal: {
type: Number,
default: 50
},
minVal: {
type: Number,
default: 50
},
maxVal: {
type: Number,
default: 1000
}
},
data() {
return {
numVal: this.curVal,
strVal: this.curVal.toString()
}
},
methods: {
onEnter() {
if(Number(this.strVal) <= this.minVal) {
this.strVal = this.minVal.toString();
this.numVal = this.minVal;
}
if(Number(this.strVal) >= this.maxVal) {
this.strVal = this.maxVal.toString();
this.numVal = this.maxVal;
} this.numVal = Number(this.strVal);
this.$emit("getNumber", this.numVal);
},
onBlur() {
this.nextTick(() => {
this.onEnter();
});
},
onReduce() {
if(Number(this.strVal) > this.minVal) {
this.strVal = Number(this.strVal);
this.numVal -= 1;
this.strVal = this.numVal.toString();
this.$emit("getNumber", this.numVal);
}
},
onIncrease() {
if(Number(this.strVal) < this.maxVal) {
this.strVal = Number(this.strVal);
this.numVal += 1;
this.strVal = this.numVal.toString();
this.$emit("getNumber", this.numVal);
}
},
resetCurVal(val) {
this.strVal = val.toString();
this.numVal = val;
this.$emit("getNumber", this.numVal);
}
}
}
</script> <style lang="less" scoped>
/*数字输入框*/
.box-disable {
pointer-events: none;
color: #686868 !important;
}
.number-box {
color: #FFF;
dispaly: felx;
flex-flow: row nowrap;
justify-content: space-between;
.btn-number {
cursor: pointer;
margin-top: 7px;
width: 15px;
height: 15px;
}
.number-container {
display: flex;
flex-flow: row nowrap;
justify-content: space-between;
flex-grow: 1;
margin: 0 10px;
background: #1F2124;
.unit {
position: absolute;
right: 35px;
}
}
}
</style>
以下为引用number-box.vue组件的index.vue内容:
<template>
<div class="main-container">
<div class="" @click="onBackOff">
</div>
<number-box ref="numRange" :curVal="currentVal" :minVal="50" :maxVal=“1000” @getNumber="getNumber" />
</div>
</template>
<script>
export default {
data() {
return {
currentVal: 30
}
},
methods: {
onBackOff() { //重置子组件输入框中的内容
this.$refs.numRange.resetCurVal(50);
},
getNumber(val) {
console.log("This is value of input ", val);
}
}
}
</script>
Vue Input输入框两侧加减框内数字组件的更多相关文章
- js实现输入框数量加减【转】
<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN" "http://www.w3.org/ ...
- Android 自定义控件 EditText输入框两边加减按钮Button
自己封装的一个控件:EditText两边放加减按钮Button来控制输入框的数值 Demo 下载地址: 第一版:http://download.csdn.net/detail/zjjne/674086 ...
- 微信小程序优化:实现picker组件中input输入框禁止输入,而只能通过picker组件选择日期
原来的代码如下: <view class="right"> <picker mode="date" value="{{mat ...
- vue input输入框长度限制
今天在开发登录页时,需要设置登录输入框的长度,输入类型为number <input type="number" maxlength="11" placeh ...
- vue input输入框联想
以下是示例,样式可以自己修改.最后是效果图,其实也挺简单的,主要是用了watch监控input输入值的变化,如果数据是请后端请求可以,先请求数据. <template> <div c ...
- input标签获取焦点时文本框内提示信息清空背景颜色发生变化
<input type="text" id="username" onfocus="myFocus(this,'#f4eaf1')" ...
- VUE -input输入框字母转大写
示例: 输入自动转--->大写 <input type="text" placeholder="请输入证件号码" maxlength="1 ...
- vue 如何实现 Input 输入框模糊查询方法
原理:原生js的indexOf() 方法,该方法将从头到尾地检索数组,看它是否含有对应的元素.开始检索的位置在数组 start 处或数组的开头(没有指定 start 参数时).如果找到一个 item, ...
- 购物车数字加减按钮HTML+CSS+JS(有需要嫌麻烦的小伙伴拿走不谢)
之前在写详情页的时候,如下图 因为自己嫌麻烦,就去看其他网站是怎么写的,想直接拿来用,后来看来看去觉得写得很麻烦,于是最后还是决定自己写,附上HTML+CSS+JS代码,一条龙一站式贴心服务2333 ...
随机推荐
- react native onEndReached频繁多次调用问题
今天被这个问题搞得头疼,写一个分页加载,但是listview的onEndReached方法老是被频繁调用,知道加载完所有的分页数据才停止. <ListView automaticallyAdju ...
- day08文件操作
今日内容 文件操作 内容详细 1.打开文件 1.open("作业讲解.py",mode="r",encoding="utf-8") 2.文件 ...
- 构建之法 chapter 8 需求分析 ——读书心得
需求分析,是软件工程开发的第一步,准确全面地找到用户的需求,尽可能满足用户的要求,是软件惺惺发展的基础.所以需求分析很重要.具体来说有以下几个步骤: 1.获取和引导需求:软件团队需要找到软件的利益相关 ...
- Linux 开(关) ICMP 回应(防止被ping)
临时生效的办法 关闭回应: [root@host ~]# echo 1 > /proc/sys/net/ipv4/icmp_echo_ignore_all // 客户端测试 ➜ ~ ping 0 ...
- 跳台阶(JAVA)
跳台阶 题目描述 一只青蛙一次可以跳上1级台阶,也可以跳上2级.求该青蛙跳上一个n级的台阶总共有多少种跳法. 思路:典型的动态规划问题,动态规划问题最关键的是把事件中的各种情形抽象为状态,然后找到前后 ...
- dataframe基础
1 df[i] 其中i是0,1,2,3,... 此时选中的是dataframe的第i列 2 dataframe查看每一列是否有缺失值 temp = data.isnull().any() #列中 ...
- C++中的内部类
1.内部类的概念 如果一个类定义在另一个类的内部,这个内部类就叫做内部类.注意此时这个内部类是一个独立的类,它不属于外部类,更不能通过外部类的对象去调用内部类.外部类对内部类没有任何优越的访问权限. ...
- apache做反向代理
实验目的 通过apache实现反向代理的功能,类似nginx反向代理和haproxy反向代理 环境准备 逻辑架构如下 前端是apche服务器,监听80端口,后端有两台web服务器,分别是node1和n ...
- vue2-通过axios实现数据请求
1.通过axios实现数据请求 vue.js默认没有提供ajax功能 所以使用vue的时候,一般都会使用axios的插件来实现ajax与后端服务器的数据交互. 注意,axios本质上就是javascr ...
- 我发起并创立了一个 Javascript 前端库 开源项目 jWebForm
在线演示地址: ( 在线演示 云平台 由 Kooboo 提供 https://www.kooboo.com/ ) 按钮: http://iwebform.kgeking.kooboo.si ...