Skip to content

Commit da6ea62

Browse files
authored
fix(Menu): 修复MenuItem 无法销毁问题 #1788 (#1857)
1 parent 3500d8a commit da6ea62

File tree

5 files changed

+49
-22
lines changed

5 files changed

+49
-22
lines changed

src/packages/__VUE/menu/index.taro.vue

+15
Original file line numberDiff line numberDiff line change
@@ -81,10 +81,25 @@ export default create({
8181
}
8282
};
8383
84+
const removeLink = (child: any) => {
85+
if (child.proxy) {
86+
let internalIndex = internalChildren.indexOf(child);
87+
if (internalIndex > -1) {
88+
internalChildren.splice(internalIndex, 1);
89+
}
90+
91+
let publicIndex = publicChildren.indexOf(child.proxy);
92+
if (internalIndex > -1) {
93+
publicChildren.splice(publicIndex, 1);
94+
}
95+
}
96+
};
97+
8498
provide(
8599
'menuParent',
86100
Object.assign(
87101
{
102+
removeLink,
88103
link,
89104
children: publicChildren,
90105
internalChildren

src/packages/__VUE/menu/index.vue

+15
Original file line numberDiff line numberDiff line change
@@ -79,10 +79,25 @@ export default create({
7979
}
8080
};
8181
82+
const removeLink = (child: any) => {
83+
if (child.proxy) {
84+
let internalIndex = internalChildren.indexOf(child);
85+
if (internalIndex > -1) {
86+
internalChildren.splice(internalIndex, 1);
87+
}
88+
89+
let publicIndex = publicChildren.indexOf(child.proxy);
90+
if (internalIndex > -1) {
91+
publicChildren.splice(publicIndex, 1);
92+
}
93+
}
94+
};
95+
8296
provide(
8397
'menuParent',
8498
Object.assign(
8599
{
100+
removeLink,
86101
link,
87102
children: publicChildren,
88103
internalChildren

src/packages/__VUE/menuitem/index.scss

+1-15
Original file line numberDiff line numberDiff line change
@@ -36,24 +36,10 @@
3636
}
3737
}
3838

39-
.menu-item__pop-container {
40-
position: fixed;
41-
top: 0;
42-
bottom: 0;
43-
right: 0;
44-
left: 0;
45-
overflow: hidden;
46-
}
47-
4839
.nut-menu__pop {
4940
transition: all 0 ease 0;
5041
transform: none;
51-
position: absolute !important;
52-
}
53-
54-
.nut-menu__overlay {
55-
position: absolute !important;
56-
top: auto;
42+
overflow: hidden;
5743
}
5844

5945
.placeholder-element {

src/packages/__VUE/menuitem/index.taro.vue

+11-5
Original file line numberDiff line numberDiff line change
@@ -9,16 +9,17 @@
99
>
1010
</div>
1111
<nut-popup
12-
class="menu-item__pop-container"
13-
:containerStyle="
12+
:style="
13+
parent.props.direction === 'down' ? { top: parent.offset.value + 'px' } : { bottom: parent.offset.value + 'px' }
14+
"
15+
:overlay-style="
1416
parent.props.direction === 'down' ? { top: parent.offset.value + 'px' } : { bottom: parent.offset.value + 'px' }
1517
"
1618
v-bind="$attrs"
1719
v-model:visible="state.showPopup"
1820
:position="parent.props.direction === 'down' ? 'top' : 'bottom'"
1921
:duration="parent.props.duration"
2022
pop-class="nut-menu__pop"
21-
overlayClass="nut-menu__overlay"
2223
:overlay="parent.props.overlay"
2324
:lockScroll="parent.props.lockScroll"
2425
@closed="handleClose"
@@ -60,7 +61,7 @@
6061
</view>
6162
</template>
6263
<script lang="ts">
63-
import { reactive, PropType, inject, getCurrentInstance, computed } from 'vue';
64+
import { reactive, PropType, inject, getCurrentInstance, computed, onUnmounted } from 'vue';
6465
import { createComponent } from '@/packages/utils/create';
6566
const { componentName, create } = createComponent('menu-item');
6667
import Icon from '../icon/index.taro.vue';
@@ -113,11 +114,16 @@ export default create({
113114
// 获取子组件自己的实例
114115
const instance = getCurrentInstance()!;
115116
116-
const { link } = parent;
117+
const { link, removeLink } = parent;
117118
118119
// @ts-ignore
119120
link(instance);
120121
122+
onUnmounted(() => {
123+
// @ts-ignore
124+
removeLink(instance);
125+
});
126+
121127
return {
122128
parent
123129
};

src/packages/__VUE/menuitem/index.vue

+7-2
Original file line numberDiff line numberDiff line change
@@ -55,7 +55,7 @@
5555
</view>
5656
</template>
5757
<script lang="ts">
58-
import { reactive, PropType, inject, getCurrentInstance, computed } from 'vue';
58+
import { reactive, PropType, inject, getCurrentInstance, computed, onUnmounted } from 'vue';
5959
import { createComponent } from '@/packages/utils/create';
6060
const { componentName, create } = createComponent('menu-item');
6161
import Icon from '../icon/index.vue';
@@ -104,11 +104,16 @@ export default create({
104104
// 获取子组件自己的实例
105105
const instance = getCurrentInstance()!;
106106
107-
const { link } = parent;
107+
const { link, removeLink } = parent;
108108
109109
// @ts-ignore
110110
link(instance);
111111
112+
onUnmounted(() => {
113+
// @ts-ignore
114+
removeLink(instance);
115+
});
116+
112117
return {
113118
parent
114119
};

0 commit comments

Comments
 (0)