当我尝试开发 Lapisan 组件时发生了一些事情。代码如下:
// Wrapper.vue
import { defineProps, ref, menonton, gunakanAtts, onMounted, onUnmounted, getCurrentInstance, } daripada "vue"; const props = defineProps({ nama: { jenis: Rentetan, lalai: "" }, zIndex: { jenis: Nombor, lalai: 0 }, }); const attrs = useAttrs(); const inst = getCurrentInstance(); const observer = ref (null); menonton ( () => [props.zIndex, props.name], () => { setBrothersAttrs(); } ); onMounted(() => { biarkan el = inst?.vnode.el; jika (el) { jika (!observer.value) observer.value = new MutationObserver(setBrothersAttrs); observer.value.observe(el.parentElement, { childList: true }); } setBrothersAttrs(); }); onUnmounted(() => { if (observer.value) observer.value.disconnect(); }); const setBrothersAttrs = () => { biarkan el = inst?.vnode.el; biarkan anak = el?.parentElement?.anak; jika (el && kanak-kanak) { untuk (biar i = 0; i < children.length; i++) { biar bro = anak-anak[i]; jika (bro === el) teruskan; bro.style.zIndex = props.zIndex; } } };
// Test.vue
// Keputusan dalam format HTML: