fix: support vue3.1

pull/4175/head
tanjinzhou 2021-06-08 14:18:54 +08:00
parent b45a6250de
commit 93c2bc1552
4 changed files with 19 additions and 12 deletions

View File

@ -42,7 +42,7 @@ const AutoComplete = defineComponent({
OptGroup: { ...OptGroup, name: 'AAutoCompleteOptGroup' }, OptGroup: { ...OptGroup, name: 'AAutoCompleteOptGroup' },
setup(props, { slots }) { setup(props, { slots }) {
warning( warning(
!('dataSource' in props || 'dataSource' in slots), !(props.dataSource !== undefined || 'dataSource' in slots),
'AutoComplete', 'AutoComplete',
'`dataSource` is deprecated, please use `options` instead.', '`dataSource` is deprecated, please use `options` instead.',
); );

View File

@ -123,7 +123,7 @@ export default defineComponent({
{ immediate: true }, { immediate: true },
); );
watchEffect(() => { watchEffect(() => {
if ('activeKey' in props) { if (props.activeKey !== undefined) {
let keys = []; let keys = [];
const menuInfo = props.activeKey const menuInfo = props.activeKey
? (keyMapStore.value[props.activeKey] as UnwrapRef<StoreMenuInfo>) ? (keyMapStore.value[props.activeKey] as UnwrapRef<StoreMenuInfo>)
@ -194,7 +194,7 @@ export default defineComponent({
selectedKeys: newSelectedKeys, selectedKeys: newSelectedKeys,
}; };
if (!shallowEqual(newSelectedKeys, mergedSelectedKeys.value)) { if (!shallowEqual(newSelectedKeys, mergedSelectedKeys.value)) {
if (!('selectedKeys' in props)) { if (props.selectedKeys === undefined) {
mergedSelectedKeys.value = newSelectedKeys; mergedSelectedKeys.value = newSelectedKeys;
} }
emit('update:selectedKeys', newSelectedKeys); emit('update:selectedKeys', newSelectedKeys);
@ -223,11 +223,10 @@ export default defineComponent({
); );
const changeActiveKeys = (keys: Key[]) => { const changeActiveKeys = (keys: Key[]) => {
if ('activeKey' in props) { if (props.activeKey === undefined) {
emit('update:activeKey', keys[keys.length - 1]);
} else {
activeKeys.value = keys; activeKeys.value = keys;
} }
emit('update:activeKey', keys[keys.length - 1]);
}; };
const disabled = computed(() => !!props.disabled); const disabled = computed(() => !!props.disabled);
const isRtl = computed(() => direction.value === 'rtl'); const isRtl = computed(() => direction.value === 'rtl');

View File

@ -7,6 +7,7 @@ import {
computed, computed,
onMounted, onMounted,
nextTick, nextTick,
watch,
} from 'vue'; } from 'vue';
import LoadingOutlined from '@ant-design/icons-vue/LoadingOutlined'; import LoadingOutlined from '@ant-design/icons-vue/LoadingOutlined';
import PropTypes from '../_util/vue-types'; import PropTypes from '../_util/vue-types';
@ -27,7 +28,6 @@ const switchProps = {
checkedChildren: PropTypes.any, checkedChildren: PropTypes.any,
unCheckedChildren: PropTypes.any, unCheckedChildren: PropTypes.any,
tabindex: PropTypes.oneOfType([PropTypes.string, PropTypes.number]), tabindex: PropTypes.oneOfType([PropTypes.string, PropTypes.number]),
defaultChecked: PropTypes.looseBool,
autofocus: PropTypes.looseBool, autofocus: PropTypes.looseBool,
loading: PropTypes.looseBool, loading: PropTypes.looseBool,
checked: PropTypes.looseBool, checked: PropTypes.looseBool,
@ -59,6 +59,14 @@ const Switch = defineComponent({
'`value` is not validate prop, do you mean `checked`?', '`value` is not validate prop, do you mean `checked`?',
); );
}); });
const checked = ref(props.checked !== undefined ? !!props.checked : !!attrs.defaultChecked);
watch(
() => props.checked,
() => {
checked.value = !!props.checked;
},
);
const configProvider = inject('configProvider', defaultConfigProvider); const configProvider = inject('configProvider', defaultConfigProvider);
const { getPrefixCls } = configProvider; const { getPrefixCls } = configProvider;
@ -75,9 +83,6 @@ const Switch = defineComponent({
const prefixCls = computed(() => { const prefixCls = computed(() => {
return getPrefixCls('switch', props.prefixCls); return getPrefixCls('switch', props.prefixCls);
}); });
const checked = computed(() => {
return 'checked' in props ? !!props.checked : !!props.defaultChecked;
});
onMounted(() => { onMounted(() => {
nextTick(() => { nextTick(() => {
@ -91,6 +96,9 @@ const Switch = defineComponent({
if (props.disabled) { if (props.disabled) {
return; return;
} }
if (props.checked === undefined) {
checked.value = check;
}
emit('update:checked', check); emit('update:checked', check);
emit('change', check, e); emit('change', check, e);
}; };

View File

@ -155,7 +155,7 @@ const Base = defineComponent<InternalBlockProps>({
); );
watchEffect(() => { watchEffect(() => {
if (!('content' in props)) { if (props.content === undefined) {
warning( warning(
!props.editable, !props.editable,
'Typography', 'Typography',
@ -437,7 +437,7 @@ const Base = defineComponent<InternalBlockProps>({
const { editing } = editable.value; const { editing } = editable.value;
const children = const children =
props.ellipsis || props.editable props.ellipsis || props.editable
? 'content' in props ? props.content !== undefined
? props.content ? props.content
: slots.default?.() : slots.default?.()
: slots.default : slots.default