-
Notifications
You must be signed in to change notification settings - Fork 3.7k
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
头条/抖音小程序不支持 $nextTick #791
Comments
没懂,你怎么调用的$nextTick,不是像下边这样吗 this.$nextTick(() => {
const query = wx.createSelectorQuery()
query.select('#a').boundingClientRect()
query.exec(function(res) {
console.log(res);
})
}) |
是的,没错,是按你说的这么调用的,我们在微信小程序里大量使用了此API。 |
跟官方没关系,这个 api 是我们自己实现的,发个示例程序 <template>
<view class="content">
<view id="a" v-if="a">AAAAAAA</view>
<button @click="go">切换</button>
</view>
</template>
<script>
export default {
data() {
return {
a: false
}
},
methods: {
go() {
this.a = !this.a
this.$nextTick(() => {
const query = uni.createSelectorQuery()
query.select('#a').boundingClientRect()
query.exec(function(res) {
console.log(res);
})
})
}
}
}
</script> |
嗯嗯,调用方法是一样的。 |
这是测试 demo. 场景: 测试方式: |
this.$refs 底层使用了 selectAllComponents 模拟,头条小程序在基础库1.16.2.0版本之前selectAllComponents是异步 api,1.16.2.0之后支持同步,稍后优化以下,保证头条基础库 1.16.2.0 版本以后可以正常 |
好的。 |
经测试,你的 demo 新版本里仍有几率出现访问不到,问题主要是你的组件是在 v-if 里边动态渲染的,onReady 只能保证首次渲染完成 //#ifdef MP-TOUTIAO
const nextTick = Vue.prototype.$nextTick
Vue.prototype.$nextTick = function(callback) {
nextTick.call(this, function() {
setTimeout(callback, 200)//自己调延迟时间
})
}
//#endif |
嗯嗯,demo只是一个简单的渲染,在我们项目里,还有比较复杂的 |
我使用了你的方法,在 demo 里能正常使用,然后我在我们项目里测试,最终还是 截图里还是undefined,我能确定这个 |
好的,收到,我们试试,非常感谢 |
我按照你的做法,build生成了uni-mp-toutiao 文件。 common.zip |
我重新做了一个demo,这个是从我们项目里抽离部分代码的demo。 记得开启不验证域名哦 |
@fxy060608 我注意到官网已经更新到2.3版本了,我用hbx |
经排查,该问题是头条小程序底层 bug 导致的,后续看是不是能绕过去。 //标识加载完成
self.isLoadConfSucc = 1;
// 延迟 resolve,避免短时间触发多次 setData
setTimeout(function(){
resolve(app.globalData[`shopsAllConf_` + $whoNo])
},10) |
好的,非常感谢 |
问题描述
目前我们的小程序在多端使用,微信小程序+支付宝+头条/抖音小程序。
在微信、支付宝中,官方都提供了
$nextTick
的API,可以检测是否dom完成。但在头条/抖音小程序里,官方没有提供此
$nextTick
API,导致有加载过程中,有很多事件和方法都无法正常使用。请问有头条/抖音小程序里,有什么办法检查dom完成吗?
The text was updated successfully, but these errors were encountered: