From 2172cce8b60c3480efb0085bfbb976ed820944b2 Mon Sep 17 00:00:00 2001 From: chenjiahan Date: Sat, 15 Aug 2020 07:20:25 +0800 Subject: [PATCH] feat: migrate Radio/RadioGroup --- components.js | 2 ++ docs/markdown/changelog-v3.zh-CN.md | 2 ++ src/radio-group/index.js | 6 ++++-- src/radio/index.js | 6 ++++-- vant.config.js | 16 ++++++++-------- 5 files changed, 20 insertions(+), 12 deletions(-) diff --git a/components.js b/components.js index 82dcf8712..ca5e12aef 100644 --- a/components.js +++ b/components.js @@ -49,4 +49,6 @@ module.exports = [ 'calendar', 'checkbox', 'checkbox-group', + 'radio', + 'radio-group', ]; diff --git a/docs/markdown/changelog-v3.zh-CN.md b/docs/markdown/changelog-v3.zh-CN.md index f8a150a2b..4a811ff48 100644 --- a/docs/markdown/changelog-v3.zh-CN.md +++ b/docs/markdown/changelog-v3.zh-CN.md @@ -37,6 +37,8 @@ Vant 遵循 [Semver](https://semver.org/lang/zh-CN/) 语义化版本规范。 - Checkbox - CheckboxGroup - Field +- Radio +- RadioGroup - Switch - Sidebar diff --git a/src/radio-group/index.js b/src/radio-group/index.js index 88755a5c5..fccb4b698 100644 --- a/src/radio-group/index.js +++ b/src/radio-group/index.js @@ -8,13 +8,15 @@ export default createComponent({ mixins: [ParentMixin('vanRadio'), FieldMixin], props: { - value: null, disabled: Boolean, direction: String, + modelValue: null, checkedColor: String, iconSize: [Number, String], }, + emits: ['change', 'update:modelValue'], + watch: { value(value) { this.$emit('change', value); @@ -24,7 +26,7 @@ export default createComponent({ render() { return (
- {this.slots()} + {this.$slots.default?.()}
); }, diff --git a/src/radio/index.js b/src/radio/index.js index 3b9584a97..ae06f3565 100644 --- a/src/radio/index.js +++ b/src/radio/index.js @@ -12,14 +12,16 @@ export default createComponent({ }), ], + emits: ['click', 'update:modelValue'], + computed: { currentValue: { get() { - return this.parent ? this.parent.value : this.value; + return this.parent ? this.parent.modelValue : this.modelValue; }, set(val) { - (this.parent || this).$emit('input', val); + (this.parent || this).$emit('update:modelValue', val); }, }, diff --git a/vant.config.js b/vant.config.js index d59c41e2d..fff4e2bad 100644 --- a/vant.config.js +++ b/vant.config.js @@ -147,10 +147,10 @@ module.exports = { path: 'picker', title: 'Picker 选择器', }, - // { - // path: 'radio', - // title: 'Radio 单选框', - // }, + { + path: 'radio', + title: 'Radio 单选框', + }, { path: 'rate', title: 'Rate 评分', @@ -481,10 +481,10 @@ module.exports = { path: 'picker', title: 'Picker', }, - // { - // path: 'radio', - // title: 'Radio', - // }, + { + path: 'radio', + title: 'Radio', + }, { path: 'rate', title: 'Rate',