mirror of
https://gitee.com/vant-contrib/vant.git
synced 2025-05-09 00:48:56 +08:00
chore: add useParent default value
This commit is contained in:
parent
d0a3726bbb
commit
25cbdecf25
@ -1,4 +1,3 @@
|
|||||||
import { ref } from 'vue';
|
|
||||||
import { createNamespace } from '../utils';
|
import { createNamespace } from '../utils';
|
||||||
import { route, routeProps } from '../utils/router';
|
import { route, routeProps } from '../utils/router';
|
||||||
import { useParent } from '../api/use-relation';
|
import { useParent } from '../api/use-relation';
|
||||||
@ -20,7 +19,7 @@ export default createComponent({
|
|||||||
},
|
},
|
||||||
|
|
||||||
setup(props, { slots }) {
|
setup(props, { slots }) {
|
||||||
useParent(ACTION_BAR_KEY, ref());
|
useParent(ACTION_BAR_KEY);
|
||||||
|
|
||||||
const renderIcon = () => {
|
const renderIcon = () => {
|
||||||
const { dot, badge, icon, color, iconClass } = props;
|
const { dot, badge, icon, color, iconClass } = props;
|
||||||
|
@ -1,10 +1,13 @@
|
|||||||
import { Ref, inject, computed, onUnmounted } from 'vue';
|
import { ref, Ref, inject, computed, onUnmounted } from 'vue';
|
||||||
|
|
||||||
export type Parent<T = unknown> = null | {
|
export type Parent<T = unknown> = null | {
|
||||||
children: Ref<Ref<T>[]>;
|
children: Ref<Ref<T>[]>;
|
||||||
};
|
};
|
||||||
|
|
||||||
export function useParent<T = unknown>(key: string, child: Ref<T>) {
|
export function useParent<T = unknown>(
|
||||||
|
key: string,
|
||||||
|
child: Ref<T> = ref() as Ref<T>
|
||||||
|
) {
|
||||||
const parent = inject<Parent<T>>(key, null);
|
const parent = inject<Parent<T>>(key, null);
|
||||||
|
|
||||||
if (parent) {
|
if (parent) {
|
||||||
|
@ -29,7 +29,7 @@ export default createComponent({
|
|||||||
setup(props, { slots }) {
|
setup(props, { slots }) {
|
||||||
const wrapper = ref(null);
|
const wrapper = ref(null);
|
||||||
const content = ref(null);
|
const content = ref(null);
|
||||||
const { parent, index } = useParent(COLLAPSE_KEY, ref());
|
const { parent, index } = useParent(COLLAPSE_KEY);
|
||||||
|
|
||||||
const currentName = computed(() =>
|
const currentName = computed(() =>
|
||||||
isDef(props.name) ? props.name : index.value
|
isDef(props.name) ? props.name : index.value
|
||||||
|
@ -1,4 +1,3 @@
|
|||||||
import { ref } from 'vue';
|
|
||||||
import { createNamespace } from '../utils';
|
import { createNamespace } from '../utils';
|
||||||
import { route, routeProps } from '../utils/router';
|
import { route, routeProps } from '../utils/router';
|
||||||
import { useParent } from '../api/use-relation';
|
import { useParent } from '../api/use-relation';
|
||||||
@ -19,7 +18,7 @@ export default createComponent({
|
|||||||
emits: ['click'],
|
emits: ['click'],
|
||||||
|
|
||||||
setup(props, { emit }) {
|
setup(props, { emit }) {
|
||||||
const { parent, index } = useParent(SIDEBAR_KEY, ref());
|
const { parent, index } = useParent(SIDEBAR_KEY);
|
||||||
|
|
||||||
return (vm) => {
|
return (vm) => {
|
||||||
const { dot, badge, title, disabled } = props;
|
const { dot, badge, title, disabled } = props;
|
||||||
@ -37,7 +36,7 @@ export default createComponent({
|
|||||||
};
|
};
|
||||||
|
|
||||||
return (
|
return (
|
||||||
<a class={bem({ select: selected.value, disabled })} onClick={onClick}>
|
<a class={bem({ select: selected, disabled })} onClick={onClick}>
|
||||||
<div class={bem('text')}>
|
<div class={bem('text')}>
|
||||||
{title}
|
{title}
|
||||||
<Badge dot={dot} badge={badge} class={bem('badge')} />
|
<Badge dot={dot} badge={badge} class={bem('badge')} />
|
||||||
|
@ -18,7 +18,6 @@ export default createComponent({
|
|||||||
setup(props, { emit, slots }) {
|
setup(props, { emit, slots }) {
|
||||||
const children = ref([]);
|
const children = ref([]);
|
||||||
const active = () => +props.modelValue;
|
const active = () => +props.modelValue;
|
||||||
|
|
||||||
const setActive = (value) => {
|
const setActive = (value) => {
|
||||||
if (value !== active()) {
|
if (value !== active()) {
|
||||||
emit('change', value);
|
emit('change', value);
|
||||||
|
Loading…
x
Reference in New Issue
Block a user