mirror of
https://github.com/youzan/vant.git
synced 2025-10-22 11:54:02 +00:00
[improvement] Use scoped-slots in Vue 2.6+ (#2688)
This commit is contained in:
@@ -1,7 +1,6 @@
|
||||
/**
|
||||
* Common part of Checkbox & Radio
|
||||
*/
|
||||
import { useSlots } from '../utils';
|
||||
import Icon from '../icon';
|
||||
import findParent from './find-parent';
|
||||
|
||||
@@ -42,18 +41,18 @@ export default (parent, bem) => ({
|
||||
},
|
||||
|
||||
render(h) {
|
||||
const { checked } = this;
|
||||
const slots = useSlots(this);
|
||||
const { slots, checked } = this;
|
||||
|
||||
const CheckIcon = slots('icon', { checked }) || (
|
||||
<Icon name="success" style={this.iconStyle} />
|
||||
);
|
||||
|
||||
const Label = slots('default') && (
|
||||
const Label = slots() && (
|
||||
<span
|
||||
class={bem('label', [this.labelPosition, { disabled: this.isDisabled }])}
|
||||
onClick={this.onClickLabel}
|
||||
>
|
||||
{slots('default')}
|
||||
{slots()}
|
||||
</span>
|
||||
);
|
||||
|
||||
|
16
packages/mixins/slots.js
Normal file
16
packages/mixins/slots.js
Normal file
@@ -0,0 +1,16 @@
|
||||
/**
|
||||
* Use scopedSlots in Vue 2.6+
|
||||
* downgrade to slots in lower version
|
||||
*/
|
||||
|
||||
export default {
|
||||
methods: {
|
||||
slots(name = 'default', props) {
|
||||
const { $slots, $scopedSlots } = this;
|
||||
if ($scopedSlots[name]) {
|
||||
return $scopedSlots[name](props);
|
||||
}
|
||||
return $slots[name];
|
||||
}
|
||||
}
|
||||
};
|
Reference in New Issue
Block a user