最近开发中遇到了一个问题,使用iview2.x的Modal组件时出现了嵌套层级异常问题,即我在Modal中嵌套了Modal(实际上我是引入的组件),嵌套的Modal层级在父级Modal的下方。
虽说一般建议尽量避免嵌套Modal的情况出现,但是业务中有时不得不需要使用这种方式。
解决方法:在父级Modal中添加属性 :transfer="false"即可
PS: 添加该属性后Modal的位置会较原来发生变化,继续使用:style="{top: '200px'}"进行调整。
<Button type="primary" @click="openFather">点我打开父级模态框</Button>
<Modal title="我是父级模态框" v-model="father" :transfer="false">
<Button type="primary" @click="openChild">点我打开嵌套的Modal框</Button>
<Modal title="我是嵌套模态框" v-model="child">
content
</Modal>
</Modal>