docs(Switch): use composition api

This commit is contained in:
chenjiahan
2020-12-09 10:33:00 +08:00
parent 84b7e69d64
commit f354513f9e
3 changed files with 58 additions and 42 deletions
+18 -13
View File
@@ -19,11 +19,12 @@ app.use(Switch);
```
```js
import { ref } from 'vue';
export default {
data() {
return {
checked: true,
};
setup() {
const checked = ref(true);
return { checked };
},
};
```
@@ -59,21 +60,25 @@ export default {
```
```js
import { ref } from 'vue';
import { Dialog } from 'vant';
export default {
data() {
return {
checked: true,
};
},
methods: {
onUpdateValue(checked) {
setup() {
const checked = ref(true);
const onUpdateValue = (newValue) => {
Dialog.confirm({
title: 'Confirm',
message: 'Are you sure to toggle switch?',
}).then(() => {
this.checked = checked;
checked.value = newValue;
});
},
};
return {
checked,
onUpdateValue,
};
},
};
```