一、问题
使用uniapp+vue3+vant-weapp开发小程序时,用到DropdownMenu组件,菜单使用Area省市联动组件,需要调用DropdownItem方法关闭当前弹窗。
vant-weapp官方文档说明,小程序写法可以通过 selectComponent(id) 可访问,uniapp中不可行。
二、解决方法
|
1 2 3 4 |
const pages = getCurrentPages() const ctx = pages[pages.length - 1] const pageCtx = ctx.selectComponent('#item').toggle() // 作用:取到某个组件的实例对象,并调用它的方法。 |