support InputNumber

support InputNumber
This commit is contained in:
梁灏 2017-03-02 13:40:09 +08:00
parent 456daf3492
commit c97c42ab2e
8 changed files with 50 additions and 14 deletions

View file

@ -11,4 +11,6 @@ value 改为了 label使用 v-model废弃 checked
### Switch
废弃checked 改为了 value使用 v-model
### Badge
class 改为了 className
class 改为了 className
### InputNumber
使用 v-model

View file

@ -31,7 +31,7 @@
- [ ] TimePicker
- [ ] Cascader
- [ ] Transfer
- [ ] InputNumber
- [x] InputNumber
- [ ] Rate
- [ ] Upload
- [ ] Form

View file

@ -92,7 +92,8 @@
return {
focused: false,
upDisabled: false,
downDisabled: false
downDisabled: false,
currentValue: this.value
};
},
computed: {
@ -164,7 +165,7 @@
}
const targetVal = Number(e.target.value);
let val = Number(this.value);
let val = Number(this.currentValue);
const step = Number(this.step);
if (isNaN(val)) {
return false;
@ -196,9 +197,11 @@
},
setValue (val) {
this.$nextTick(() => {
this.value = val;
this.currentValue = val;
this.$emit('input', val);
this.$emit('on-change', val);
this.$dispatch('on-form-change', val);
// todo
// this.$dispatch('on-form-change', val);
});
},
focus () {
@ -224,7 +227,7 @@
if (isValueNumber(val)) {
val = Number(val);
this.value = val;
this.currentValue = val;
if (val > max) {
this.setValue(max);
@ -234,7 +237,7 @@
this.setValue(val);
}
} else {
event.target.value = this.value;
event.target.value = this.currentValue;
}
},
changeVal (val) {
@ -250,11 +253,14 @@
}
}
},
compiled () {
this.changeVal(this.value);
mounted () {
this.changeVal(this.currentValue);
},
watch: {
value (val) {
this.currentValue = val;
},
currentValue (val) {
this.changeVal(val);
}
}

View file

@ -18,7 +18,7 @@ import Checkbox from './components/checkbox';
// import Form from './components/form';
import Icon from './components/icon';
import Input from './components/input';
// import InputNumber from './components/input-number';
import InputNumber from './components/input-number';
// import LoadingBar from './components/loading-bar';
// import Menu from './components/menu';
// import Message from './components/message';
@ -74,7 +74,7 @@ const iview = {
Icon,
// iInput: Input,
Input,
// InputNumber,
InputNumber,
// LoadingBar,
// Menu,
// MenuGroup: Menu.Group,

View file

@ -25,6 +25,7 @@ li + li { border-left: solid 1px #bbb; padding-left: 10px; margin-left: 10px; }
<li><router-link to="/alert">Alert</router-link></li>
<li><router-link to="/badge">Badge</router-link></li>
<li><router-link to="/tag">Tag</router-link></li>
<li><router-link to="/input-number">InputNumber</router-link></li>
</ul>
</nav>
<router-view></router-view>

View file

@ -64,6 +64,10 @@ const router = new VueRouter({
{
path: '/tag',
component: require('./routers/tag.vue')
},
{
path: '/input-number',
component: require('./routers/input-number.vue')
}
]
});

View file

@ -0,0 +1,25 @@
<template>
<div>
<Input-number :max="10" :min="-1" v-model="v1"></Input-number>
{{ v1 }}
<div @click="c">change v1</div>
<Input-number disabled :max="10" :min="1" :step="1.2" v-model="v2"></Input-number>
</div>
</template>
<script>
export default {
props: {},
data () {
return {
v1: 1,
v2: 1
};
},
computed: {},
methods: {
c () {
this.v1 = 5;
}
}
};
</script>

View file

@ -35,9 +35,7 @@
</div>
</template>
<script>
import { Tag, Modal, iButton } from 'iview';
export default {
components: { Tag, Modal, iButton },
data () {
return {
modal1: false,