controller: web_webview.WebviewController = new web_webview.WebviewController()
onPageShow() {
const params:Params = router.getParams() as Params; // 获取传递过来的参数对象
if (params) {
let resultJson: Params = new Params();
resultJson.item=params.item;
this.AdData=resultJson.item
this.url=this.AdData.ad_url
console.info('http opageshow:' + this.url);
//日志 http opageshow: https://www.huawei.com/
}
}
build() {
Column() {
this.Title()
Web({src:this.url, controller: this.controller })
// Web({ src: 'https://www.huawei.com', controller: this.controller })
// 这样可以显示。是哪里不对?
}
.width(CommonConstants.FULL_WIDTH)
.height(CommonConstants.FULL_HEIGHT)
.backgroundColor($r('app.color.page_background'))
}
从代码里看到渲染web是在build方法内,而获取url是在onPageShow方法内,由于build先于onPageShow执行,因此加载web时并没有获取到url,应该在 aboutToAppear方法内获取url,这样即可正确加载