Commit c97c42ab2e4e954aa62fc846b7473f8462353d8c

Authored by 梁灏
1 parent 456daf34

support InputNumber

support InputNumber
@@ -11,4 +11,6 @@ value 改为了 label,使用 v-model,废弃 checked @@ -11,4 +11,6 @@ value 改为了 label,使用 v-model,废弃 checked
11 ### Switch 11 ### Switch
12 废弃checked, 改为了 value,使用 v-model 12 废弃checked, 改为了 value,使用 v-model
13 ### Badge 13 ### Badge
14 -class 改为了 className  
15 \ No newline at end of file 14 \ No newline at end of file
  15 +class 改为了 className
  16 +### InputNumber
  17 +使用 v-model
16 \ No newline at end of file 18 \ No newline at end of file
@@ -31,7 +31,7 @@ @@ -31,7 +31,7 @@
31 - [ ] TimePicker 31 - [ ] TimePicker
32 - [ ] Cascader 32 - [ ] Cascader
33 - [ ] Transfer 33 - [ ] Transfer
34 -- [ ] InputNumber 34 +- [x] InputNumber
35 - [ ] Rate 35 - [ ] Rate
36 - [ ] Upload 36 - [ ] Upload
37 - [ ] Form 37 - [ ] Form
src/components/input-number/input-number.vue
@@ -92,7 +92,8 @@ @@ -92,7 +92,8 @@
92 return { 92 return {
93 focused: false, 93 focused: false,
94 upDisabled: false, 94 upDisabled: false,
95 - downDisabled: false 95 + downDisabled: false,
  96 + currentValue: this.value
96 }; 97 };
97 }, 98 },
98 computed: { 99 computed: {
@@ -164,7 +165,7 @@ @@ -164,7 +165,7 @@
164 } 165 }
165 166
166 const targetVal = Number(e.target.value); 167 const targetVal = Number(e.target.value);
167 - let val = Number(this.value); 168 + let val = Number(this.currentValue);
168 const step = Number(this.step); 169 const step = Number(this.step);
169 if (isNaN(val)) { 170 if (isNaN(val)) {
170 return false; 171 return false;
@@ -196,9 +197,11 @@ @@ -196,9 +197,11 @@
196 }, 197 },
197 setValue (val) { 198 setValue (val) {
198 this.$nextTick(() => { 199 this.$nextTick(() => {
199 - this.value = val; 200 + this.currentValue = val;
  201 + this.$emit('input', val);
200 this.$emit('on-change', val); 202 this.$emit('on-change', val);
201 - this.$dispatch('on-form-change', val); 203 + // todo 事件
  204 +// this.$dispatch('on-form-change', val);
202 }); 205 });
203 }, 206 },
204 focus () { 207 focus () {
@@ -224,7 +227,7 @@ @@ -224,7 +227,7 @@
224 227
225 if (isValueNumber(val)) { 228 if (isValueNumber(val)) {
226 val = Number(val); 229 val = Number(val);
227 - this.value = val; 230 + this.currentValue = val;
228 231
229 if (val > max) { 232 if (val > max) {
230 this.setValue(max); 233 this.setValue(max);
@@ -234,7 +237,7 @@ @@ -234,7 +237,7 @@
234 this.setValue(val); 237 this.setValue(val);
235 } 238 }
236 } else { 239 } else {
237 - event.target.value = this.value; 240 + event.target.value = this.currentValue;
238 } 241 }
239 }, 242 },
240 changeVal (val) { 243 changeVal (val) {
@@ -250,11 +253,14 @@ @@ -250,11 +253,14 @@
250 } 253 }
251 } 254 }
252 }, 255 },
253 - compiled () {  
254 - this.changeVal(this.value); 256 + mounted () {
  257 + this.changeVal(this.currentValue);
255 }, 258 },
256 watch: { 259 watch: {
257 value (val) { 260 value (val) {
  261 + this.currentValue = val;
  262 + },
  263 + currentValue (val) {
258 this.changeVal(val); 264 this.changeVal(val);
259 } 265 }
260 } 266 }
@@ -18,7 +18,7 @@ import Checkbox from './components/checkbox'; @@ -18,7 +18,7 @@ import Checkbox from './components/checkbox';
18 // import Form from './components/form'; 18 // import Form from './components/form';
19 import Icon from './components/icon'; 19 import Icon from './components/icon';
20 import Input from './components/input'; 20 import Input from './components/input';
21 -// import InputNumber from './components/input-number'; 21 +import InputNumber from './components/input-number';
22 // import LoadingBar from './components/loading-bar'; 22 // import LoadingBar from './components/loading-bar';
23 // import Menu from './components/menu'; 23 // import Menu from './components/menu';
24 // import Message from './components/message'; 24 // import Message from './components/message';
@@ -74,7 +74,7 @@ const iview = { @@ -74,7 +74,7 @@ const iview = {
74 Icon, 74 Icon,
75 // iInput: Input, 75 // iInput: Input,
76 Input, 76 Input,
77 - // InputNumber, 77 + InputNumber,
78 // LoadingBar, 78 // LoadingBar,
79 // Menu, 79 // Menu,
80 // MenuGroup: Menu.Group, 80 // MenuGroup: Menu.Group,
@@ -25,6 +25,7 @@ li + li { border-left: solid 1px #bbb; padding-left: 10px; margin-left: 10px; } @@ -25,6 +25,7 @@ li + li { border-left: solid 1px #bbb; padding-left: 10px; margin-left: 10px; }
25 <li><router-link to="/alert">Alert</router-link></li> 25 <li><router-link to="/alert">Alert</router-link></li>
26 <li><router-link to="/badge">Badge</router-link></li> 26 <li><router-link to="/badge">Badge</router-link></li>
27 <li><router-link to="/tag">Tag</router-link></li> 27 <li><router-link to="/tag">Tag</router-link></li>
  28 + <li><router-link to="/input-number">InputNumber</router-link></li>
28 </ul> 29 </ul>
29 </nav> 30 </nav>
30 <router-view></router-view> 31 <router-view></router-view>
@@ -64,6 +64,10 @@ const router = new VueRouter({ @@ -64,6 +64,10 @@ const router = new VueRouter({
64 { 64 {
65 path: '/tag', 65 path: '/tag',
66 component: require('./routers/tag.vue') 66 component: require('./routers/tag.vue')
  67 + },
  68 + {
  69 + path: '/input-number',
  70 + component: require('./routers/input-number.vue')
67 } 71 }
68 ] 72 ]
69 }); 73 });
test/routers/input-number.vue 0 → 100644
  1 +<template>
  2 + <div>
  3 + <Input-number :max="10" :min="-1" v-model="v1"></Input-number>
  4 + {{ v1 }}
  5 + <div @click="c">change v1</div>
  6 + <Input-number disabled :max="10" :min="1" :step="1.2" v-model="v2"></Input-number>
  7 + </div>
  8 +</template>
  9 +<script>
  10 + export default {
  11 + props: {},
  12 + data () {
  13 + return {
  14 + v1: 1,
  15 + v2: 1
  16 + };
  17 + },
  18 + computed: {},
  19 + methods: {
  20 + c () {
  21 + this.v1 = 5;
  22 + }
  23 + }
  24 + };
  25 +</script>
0 \ No newline at end of file 26 \ No newline at end of file
test/routers/tag.vue
@@ -35,9 +35,7 @@ @@ -35,9 +35,7 @@
35 </div> 35 </div>
36 </template> 36 </template>
37 <script> 37 <script>
38 - import { Tag, Modal, iButton } from 'iview';  
39 export default { 38 export default {
40 - components: { Tag, Modal, iButton },  
41 data () { 39 data () {
42 return { 40 return {
43 modal1: false, 41 modal1: false,