chore(Sidebar): use relation

This commit is contained in:
chenjiahan 2020-09-26 10:57:53 +08:00
parent dfad7b14af
commit d762c23044
2 changed files with 7 additions and 5 deletions

View File

@ -1,6 +1,6 @@
import { createNamespace } from '../utils';
import { useParent } from '../composition/use-relation';
import { useRoute, routeProps } from '../composition/use-route';
import { useParent } from '../composition/use-parent';
import { SIDEBAR_KEY } from '../sidebar';
import Badge from '../badge';

View File

@ -1,5 +1,6 @@
import { watch, provide, reactive } from 'vue';
import { watch } from 'vue';
import { createNamespace } from '../utils';
import { useChildren } from '../composition/use-relation';
const [createComponent, bem] = createNamespace('sidebar');
@ -16,8 +17,10 @@ export default createComponent({
emits: ['change', 'update:modelValue'],
setup(props, { emit, slots }) {
const children = reactive([]);
const { linkChildren } = useChildren(SIDEBAR_KEY);
const active = () => +props.modelValue;
const setActive = (value) => {
if (value !== active()) {
emit('change', value);
@ -26,10 +29,9 @@ export default createComponent({
watch(active, setActive);
provide(SIDEBAR_KEY, {
linkChildren({
emit,
active,
children,
setActive,
});