#开发模式,已经选择不校验合法域名.调试基础库3.7.12
#wxml就这一句话,小程序中能正常打开页面浏览。
<web-view id="myWebView" src="http://192.168.1.6/pages/addPoint.html" bindload="onWebViewLoad"></web-view>
#但在.js文件中
Page({
onReady(){
setTimeout(() => {
const webViewComponent = this.selectComponent("#myWebView");
if (!webViewComponent) {
console.error("延迟获取仍失败,检查是否有多个同名 id 或标签错误");
}
}, 1000);
}
})
#webViewComponent始终是null
const query = wx.createSelectorQuery(); query.select('#myWebView').boundingClientRect(rect => { console.log(rect); }).exec();
wx.createSelectorQuery()这个也不行吗
wx.createSelectorQuery()
.select('#myWebView') // 选择具有指定 id 的 web-view 组件
.node((res) => {
if (res[0] && res[0].node) {
const webViewNode = res[0].node; // 获取 web-view 节点实例
console.log("web-view 节点获取成功", webViewNode);
} else {
console.error("未获取到 web-view 节点", res);
}
})
.exec();
//结果同样是找不到节点