mirror of
https://gitee.com/vant-contrib/vant.git
synced 2025-04-23 18:00:27 +08:00
docs(Stepper): use composition api
This commit is contained in:
parent
9af0840f36
commit
7e03486501
@ -19,11 +19,12 @@ app.use(Stepper);
|
|||||||
```
|
```
|
||||||
|
|
||||||
```js
|
```js
|
||||||
|
import { ref } from 'vue';
|
||||||
|
|
||||||
export default {
|
export default {
|
||||||
data() {
|
setup() {
|
||||||
return {
|
const value = ref(1);
|
||||||
value: 1,
|
return { value };
|
||||||
};
|
|
||||||
},
|
},
|
||||||
};
|
};
|
||||||
```
|
```
|
||||||
@ -77,24 +78,29 @@ export default {
|
|||||||
```
|
```
|
||||||
|
|
||||||
```js
|
```js
|
||||||
|
import { ref } from 'vue';
|
||||||
import { Toast } from 'vant';
|
import { Toast } from 'vant';
|
||||||
|
|
||||||
export default {
|
export default {
|
||||||
data() {
|
setup() {
|
||||||
return {
|
const value = ref(1);
|
||||||
value: 1,
|
|
||||||
};
|
let timer;
|
||||||
},
|
const onChange = (newValue) => {
|
||||||
methods: {
|
if (newValue === value.value) {
|
||||||
onChange(value) {
|
return;
|
||||||
|
}
|
||||||
|
|
||||||
Toast.loading({ forbidClick: true });
|
Toast.loading({ forbidClick: true });
|
||||||
|
|
||||||
clearTimeout(this.timer);
|
clearTimeout(this.timer);
|
||||||
this.timer = setTimeout(() => {
|
timer = setTimeout(() => {
|
||||||
Toast.clear();
|
Toast.clear();
|
||||||
this.value = value;
|
value.value = newValue;
|
||||||
}, 500);
|
}, 500);
|
||||||
},
|
};
|
||||||
|
|
||||||
|
return { value };
|
||||||
},
|
},
|
||||||
};
|
};
|
||||||
```
|
```
|
||||||
|
@ -25,11 +25,12 @@ app.use(Stepper);
|
|||||||
```
|
```
|
||||||
|
|
||||||
```js
|
```js
|
||||||
|
import { ref } from 'vue';
|
||||||
|
|
||||||
export default {
|
export default {
|
||||||
data() {
|
setup() {
|
||||||
return {
|
const value = ref(1);
|
||||||
value: 1,
|
return { value };
|
||||||
};
|
|
||||||
},
|
},
|
||||||
};
|
};
|
||||||
```
|
```
|
||||||
@ -99,25 +100,29 @@ export default {
|
|||||||
```
|
```
|
||||||
|
|
||||||
```js
|
```js
|
||||||
|
import { ref } from 'vue';
|
||||||
import { Toast } from 'vant';
|
import { Toast } from 'vant';
|
||||||
|
|
||||||
export default {
|
export default {
|
||||||
data() {
|
setup() {
|
||||||
return {
|
const value = ref(1);
|
||||||
value: 1,
|
|
||||||
};
|
let timer;
|
||||||
},
|
const onChange = (newValue) => {
|
||||||
methods: {
|
if (newValue === value.value) {
|
||||||
onChange(value) {
|
return;
|
||||||
|
}
|
||||||
|
|
||||||
Toast.loading({ forbidClick: true });
|
Toast.loading({ forbidClick: true });
|
||||||
|
|
||||||
clearTimeout(this.timer);
|
clearTimeout(this.timer);
|
||||||
this.timer = setTimeout(() => {
|
timer = setTimeout(() => {
|
||||||
Toast.clear();
|
Toast.clear();
|
||||||
// 注意此时修改 value 后会再次触发 change 事件
|
value.value = newValue;
|
||||||
this.value = value;
|
|
||||||
}, 500);
|
}, 500);
|
||||||
},
|
};
|
||||||
|
|
||||||
|
return { value };
|
||||||
},
|
},
|
||||||
};
|
};
|
||||||
```
|
```
|
||||||
|
@ -46,6 +46,9 @@
|
|||||||
</template>
|
</template>
|
||||||
|
|
||||||
<script>
|
<script>
|
||||||
|
import { reactive, toRefs } from 'vue';
|
||||||
|
import Toast from '../../toast';
|
||||||
|
|
||||||
export default {
|
export default {
|
||||||
i18n: {
|
i18n: {
|
||||||
'zh-CN': {
|
'zh-CN': {
|
||||||
@ -70,8 +73,8 @@ export default {
|
|||||||
},
|
},
|
||||||
},
|
},
|
||||||
|
|
||||||
data() {
|
setup() {
|
||||||
return {
|
const state = reactive({
|
||||||
stepper1: 1,
|
stepper1: 1,
|
||||||
stepper2: 1,
|
stepper2: 1,
|
||||||
stepper3: 1,
|
stepper3: 1,
|
||||||
@ -82,19 +85,27 @@ export default {
|
|||||||
stepper8: 1,
|
stepper8: 1,
|
||||||
stepperRound: 1,
|
stepperRound: 1,
|
||||||
disabledInput: 1,
|
disabledInput: 1,
|
||||||
};
|
});
|
||||||
},
|
|
||||||
|
|
||||||
methods: {
|
let timer;
|
||||||
onChange(value) {
|
const onChange = (newValue) => {
|
||||||
this.$toast.loading({ forbidClick: true });
|
if (newValue === state.stepper6) {
|
||||||
|
return;
|
||||||
|
}
|
||||||
|
|
||||||
clearTimeout(this.timer);
|
Toast.loading({ forbidClick: true });
|
||||||
this.timer = setTimeout(() => {
|
|
||||||
this.stepper6 = value;
|
clearTimeout(timer);
|
||||||
this.$toast.clear();
|
timer = setTimeout(() => {
|
||||||
|
state.stepper6 = newValue;
|
||||||
|
Toast.clear();
|
||||||
}, 500);
|
}, 500);
|
||||||
},
|
};
|
||||||
|
|
||||||
|
return {
|
||||||
|
...toRefs(state),
|
||||||
|
onChange,
|
||||||
|
};
|
||||||
},
|
},
|
||||||
};
|
};
|
||||||
</script>
|
</script>
|
||||||
|
Loading…
x
Reference in New Issue
Block a user