1, 先看原来的代码
import web_webview from '@ohos.web.webview';
interface PerUrl {
url: string,
age: number
}
@Component
export struct Url {
controller: web_webview.WebviewController = new web_webview.WebviewController();
ports: web_webview.WebMessagePort[] = [];
@Link
sonUrl:PerUrl
build() {
Column() {
Text('url的值'+ `${this.sonUrl.url} 今年 ${this.sonUrl.age} 岁`)
Web({ src: this.sonUrl.url, controller: this.controller })
}
}
}
2, 看看解决方案 加上 这两行代码
.javaScriptAccess(true)
.domStorageAccess(true)
build() {
Column() {
Text('url的值'+ `${this.sonUrl.url} 今年 ${this.sonUrl.age} 岁`)
Web({ src: this.sonUrl.url, controller: this.controller })
.javaScriptAccess(true)
.domStorageAccess(true)
}
}
}