mirror of
https://gitee.com/vant-contrib/vant.git
synced 2025-04-24 18:36:51 +08:00
chore(Sidebar): use relation
This commit is contained in:
parent
dfad7b14af
commit
d762c23044
@ -1,6 +1,6 @@
|
|||||||
import { createNamespace } from '../utils';
|
import { createNamespace } from '../utils';
|
||||||
|
import { useParent } from '../composition/use-relation';
|
||||||
import { useRoute, routeProps } from '../composition/use-route';
|
import { useRoute, routeProps } from '../composition/use-route';
|
||||||
import { useParent } from '../composition/use-parent';
|
|
||||||
import { SIDEBAR_KEY } from '../sidebar';
|
import { SIDEBAR_KEY } from '../sidebar';
|
||||||
import Badge from '../badge';
|
import Badge from '../badge';
|
||||||
|
|
||||||
|
@ -1,5 +1,6 @@
|
|||||||
import { watch, provide, reactive } from 'vue';
|
import { watch } from 'vue';
|
||||||
import { createNamespace } from '../utils';
|
import { createNamespace } from '../utils';
|
||||||
|
import { useChildren } from '../composition/use-relation';
|
||||||
|
|
||||||
const [createComponent, bem] = createNamespace('sidebar');
|
const [createComponent, bem] = createNamespace('sidebar');
|
||||||
|
|
||||||
@ -16,8 +17,10 @@ export default createComponent({
|
|||||||
emits: ['change', 'update:modelValue'],
|
emits: ['change', 'update:modelValue'],
|
||||||
|
|
||||||
setup(props, { emit, slots }) {
|
setup(props, { emit, slots }) {
|
||||||
const children = reactive([]);
|
const { linkChildren } = useChildren(SIDEBAR_KEY);
|
||||||
|
|
||||||
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);
|
||||||
@ -26,10 +29,9 @@ export default createComponent({
|
|||||||
|
|
||||||
watch(active, setActive);
|
watch(active, setActive);
|
||||||
|
|
||||||
provide(SIDEBAR_KEY, {
|
linkChildren({
|
||||||
emit,
|
emit,
|
||||||
active,
|
active,
|
||||||
children,
|
|
||||||
setActive,
|
setActive,
|
||||||
});
|
});
|
||||||
|
|
||||||
|
Loading…
x
Reference in New Issue
Block a user