太感谢了!! 自定义组件节点增加选择器 真的是没想道
【已解决】页面this.createSelectorQuery()为什么查不到自定义组件实例?自定义组件: <text class="t">custom component</text> 页面: Component({ lifetimes: { attached() { this.createSelectorQuery().select('.t').boundingClientRect( r => { console.log(r) // 输出 null } ).exec() } } }) --- 【已解决】 小程序的自定义组件和React是不同的。 当你这样定义一个组件: <text class="t">custom component</text> 然后在页面引用: { "usingComponents": { "c": "../components/c/index" } } wxml中的实际布局是这样的: <page> <c> <text class="t">custom component</text> </c> </page> text上多出一层c。 页面获取自定义组件实例,首先须定位到该自定义组件的外层节点,通过该外层节点再定位自定义组件的内部节点,这样才能selectorQuery才能查到自定义组件的内部节点,上面的代码试图在页面直接访问自定义组件内部节点,永远返回 null。 页面引用: <!-- 此处必须显示指定一个class,服务于页面的 this.selectComponent() --> <c class="c"/> // page.js Component({ lifetimes: { attached() { this.createSelectorQuery().in(this.selectComponent('.c')).select('.t').boundingClientRect( r => { console.log(r) } ).exec() } } }) 输出: { "bottom": 22, "dataset": {}, "height": 22, "id": "", "left": 0, "right": 142.875, "top": 0, "width": 142.875 } 代码片段:https://developers.weixin.qq.com/s/rfCnXPmI7eGp --- ps:页面在引用自定义组件时还要额外添加class,这真的很多余,好奇为什么要设计成这样。
2023-08-14赞同!!!
关于 ComponentWithStore 和 ComponentWithComputed?我想同时使用 ComponentWithStore 和 ComponentWithComputed 怎么用? API 设计的时候就没考虑过这种情况吗? TypeScript 的类型这么难用,还有问题要 50 个字以内真的很蠢
2023-07-19wx.getAccountInfoSync()?
小程序到底是怎么基于不同环境开发的?比如我需要每个在sit、uat和prod环境上开发,需要每个环境都申请一个小程序吗?还是说开发版就是基于sit环境开发的,体验版就可以基于uat环境开发,先上版就基于prod环境开发
2023-07-07