Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

字节小程序 - uni-popup 内部渲染 uni-forms, ref 获取不到 #336

Open
AnaniZhu opened this issue Jul 1, 2021 · 8 comments
Open
Assignees
Labels
bug Something isn't working

Comments

@AnaniZhu
Copy link

AnaniZhu commented Jul 1, 2021

平台: 字节小程序

依赖:
"@dcloudio/uni-ui": "1.3.4"
"@dcloudio/uni-mp-toutiao": "2.0.0-29820201110001",

HTML 模板

<view>
  <uni-popup ref="popup">
     <uni-forms v-model="data" ref="form">
		<uni-forms-item label="邀请码" name="token" required>
          <uni-easyinput
            v-model="formData.token"
            type="text"
            placeholder="请输入课程邀请码"
          />
        </uni-forms-item>
	</uni-form>

     <button @click="submit">提交</button>
   </uni-popup>
</view>

类似上面的模板,在弹窗打开后,点击按钮提交表单时,this.$refs.form 获取不到。
查看下源码是 uni-popop 和 uni-transition 内部是用 v-if 切换显示/隐藏状态的,改成 v-show 就能正常获取 this.$refs.form.

@Fasttian
Copy link
Contributor

Fasttian commented Jul 1, 2021

在 onReady 里去取 ref

@AnaniZhu
Copy link
Author

AnaniZhu commented Jul 1, 2021

在 onReady 里去取 ref

@Fasttian onReady 是页面层级的声明周期,但是可能有很多层嵌套的组件,某一个深层组件里用到了一个弹窗,弹窗里有个表单。这样传递关系太复杂了吧。

而且一个组件可能被多个页面使用,组件内部获取 ref 应该跟页面是解耦的吧?

@Fasttian
Copy link
Contributor

Fasttian commented Jul 1, 2021

刚才说的不对,打开弹窗后,在下一帧 this.nextTick里去取 ref,弹框还没渲染好。

@AnaniZhu
Copy link
Author

AnaniZhu commented Jul 1, 2021

刚才说的不对,打开弹窗后,在下一帧 this.nextTick里去取 ref,弹框还没渲染好。

弹窗是一直都打开的,弹窗里面有一个表单,我是在打开弹窗后,填写完表单,最后点提交按钮的时候去获取 $refs 的,这个时候依旧拿不到。
可能是 字节小程序 的策略问题?在 字节小程序开发者工具v3.0.9 或者 抖音app小程序 稳定复现

@Fasttian
Copy link
Contributor

Fasttian commented Jul 1, 2021

确认是个bug, 字节小程序里,在 slot (popup的slot)里取 ref 取不到。目前你可以先v-show的方式规避。

@AnaniZhu
Copy link
Author

AnaniZhu commented Jul 1, 2021

确认是个bug, 字节小程序里,在 slot (popup的slot)里取 ref 取不到。目前你可以先v-show的方式规避。

v-if 是 uni-popup 和 uni-transition 的内部实现,我只能先把 uni-popup 的源码拷贝到项目暂时维护了

@Fasttian Fasttian added the bug Something isn't working label Jul 2, 2021
@Fasttian Fasttian self-assigned this Jul 2, 2021
@xiaojinxuan186
Copy link

现在依旧存在这个问题,没有解决

@18148764734
Copy link
Contributor

现在依旧存在这个问题,没有解决

现版本我测试了一下,发现可以获取到表单refs,能提供一下一个简单复现的测试工程zip附件吗

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
bug Something isn't working
Projects
None yet
Development

No branches or pull requests

5 participants