chore: merge src and src-next
This commit is contained in:
@@ -54,7 +54,7 @@ export default {
|
||||
### Async Control
|
||||
|
||||
```html
|
||||
<van-switch :value="checked" @input="onInput" />
|
||||
<van-switch :model-value="checked" @update:model:value="onUpdateValue" />
|
||||
```
|
||||
|
||||
```js
|
||||
@@ -65,7 +65,7 @@ export default {
|
||||
};
|
||||
},
|
||||
methods: {
|
||||
onInput(checked) {
|
||||
onUpdateValue(checked) {
|
||||
Dialog.confirm({
|
||||
title: 'Confirm',
|
||||
message: 'Are you sure to toggle switch?',
|
||||
|
||||
@@ -63,10 +63,10 @@ export default {
|
||||
|
||||
### 异步控制
|
||||
|
||||
需要异步控制开关时,可以使用`value`属性和`input`事件代替`v-model`,并在`input`事件回调函数中手动处理开关状态
|
||||
需要异步控制开关时,可以使用 `modelValue` 属性和 `update:model-value` 事件代替 `v-model`,并在事件回调函数中手动处理开关状态。
|
||||
|
||||
```html
|
||||
<van-switch :value="checked" @input="onInput" />
|
||||
<van-switch :model-value="checked" @update:model:value="onUpdateValue" />
|
||||
```
|
||||
|
||||
```js
|
||||
@@ -77,7 +77,7 @@ export default {
|
||||
};
|
||||
},
|
||||
methods: {
|
||||
onInput(checked) {
|
||||
onUpdateValue(checked) {
|
||||
Dialog.confirm({
|
||||
title: '提醒',
|
||||
message: '是否切换开关?',
|
||||
|
||||
@@ -25,12 +25,14 @@
|
||||
</demo-block>
|
||||
|
||||
<demo-block :title="t('asyncControl')">
|
||||
<van-switch :value="checked4" @input="onInput" />
|
||||
<van-switch :model-value="checked4" @update:model-value="onInput" />
|
||||
</demo-block>
|
||||
|
||||
<demo-block :title="t('withCell')">
|
||||
<van-cell center :title="t('title')">
|
||||
<van-switch v-model="checked5" slot="right-icon" size="24" />
|
||||
<template #right-icon>
|
||||
<van-switch v-model="checked5" size="24" />
|
||||
</template>
|
||||
</van-cell>
|
||||
</demo-block>
|
||||
</demo-section>
|
||||
|
||||
+4
-2
@@ -15,9 +15,11 @@ export default createComponent({
|
||||
|
||||
props: switchProps,
|
||||
|
||||
emits: ['click', 'change', 'update:modelValue'],
|
||||
|
||||
computed: {
|
||||
checked() {
|
||||
return this.value === this.activeValue;
|
||||
return this.modelValue === this.activeValue;
|
||||
},
|
||||
|
||||
style() {
|
||||
@@ -34,7 +36,7 @@ export default createComponent({
|
||||
|
||||
if (!this.disabled && !this.loading) {
|
||||
const newValue = this.checked ? this.inactiveValue : this.activeValue;
|
||||
this.$emit('input', newValue);
|
||||
this.$emit('update:modelValue', newValue);
|
||||
this.$emit('change', newValue);
|
||||
}
|
||||
},
|
||||
|
||||
@@ -4,9 +4,9 @@
|
||||
|
||||
export type SharedSwitchProps = {
|
||||
size?: string | number;
|
||||
value?: any;
|
||||
loading?: boolean;
|
||||
disabled?: boolean;
|
||||
modelValue?: any;
|
||||
activeValue: any;
|
||||
inactiveValue: any;
|
||||
activeColor?: string;
|
||||
@@ -15,9 +15,9 @@ export type SharedSwitchProps = {
|
||||
|
||||
export const switchProps = {
|
||||
size: [Number, String],
|
||||
value: null as any,
|
||||
loading: Boolean,
|
||||
disabled: Boolean,
|
||||
modelValue: null as any,
|
||||
activeColor: String,
|
||||
inactiveColor: String,
|
||||
activeValue: {
|
||||
|
||||
Reference in New Issue
Block a user