Vant: 给Popup组件getContainer属性设置一个页面内的元素,在返回路由时会报错

Created on 25 Jan 2019  ·  9Comments  ·  Source: youzan/vant

IMPORTANT: Please use the following link to create a new issue. If your issue was not created using the app above, it will be closed immediately.

注意:请按照下面的模板来新建 issue,不规范的 issue 会被立即关闭.
Describe the bug
A clear description of what the bug is.
给Popup组件getContainer属性设置一个页面内的元素,在返回路由时,会报错,错误请查看截图

Screenshots
Add screenshots to help explain your problem.
异常截图

Environment

  • Device: Android
  • Browser: 企业微信
  • Vant Version: 1.5.7

Reproduce
Provide the steps to reproduce and if possible a minimal demo of the problem via jsfiddle.
https://jsfiddle.net/dfarLdko/522/

🐞 bug

All 9 comments

在 vant源码 mixins/popup/index.js下面,异常代码如下
`
beforeDestroy() {
this.close();

if (this.getContainer) {
  this.$parent.$el.appendChild(this.$el);
}

},
`
如果 getContainer存在但是 this.$parent.$el不存在的话,会报错,望修改

请教你怎么用到popup里mixins属性的,我用的组件里连这2个属性都没有,作者说在mixins里面,但是怎么用呢

overlay-class | 自定义蒙层类名 | String | - | -
overlay-style | 自定义蒙层样式 | Object | - | -

请教你怎么用到popup里mixins属性的,我用的组件里连这2个属性都没有,作者说在mixins里面,但是怎么用呢

overlay-class | 自定义蒙层类名 | String | - | -
overlay-style | 自定义蒙层样式 | Object | - | -

如果是mixins里面props的值,可以直接使用

@snowzijun 感谢反馈,我们会在下个版本添加上面的容错代码

已在 1.6.0 版本修复

vant 1.6.17, chrome 浏览器依然会遇到这个问题, 我把 get-container 设置成了 body, 因为我看到文档里有这样的用法, 结果就报上面那个错了, 而且我试了试,挂载到 #app 下也会报一样的错, 在我的 case 里, this.$parent.$el 是
image


最后发现给 popup 外面包层 div 就好了...看来是不能在一个组件里顶层元素就是 popup 啊

@chenjiahan 同遇到楼上同学的问题。感觉这个bug还没解决彻底

遇到与楼上两位相同的问题,this.$parent.$el与this.$el是同个元素,appendChild报错了

目前 get-container 确实不允许在顶层元素使用,这个是框架限制的,暂时木有解决方法,套一层 div 可以解决

Was this page helpful?
0 / 5 - 0 ratings