@Component
struct Index {
private webviewController: WebviewController = new WebviewController()
private canGoBack: boolean = false
build() {
Column({ space: 50 }) {
Webview({
src: ' https://www.example.com ',
controller: this.webviewController
})
.onPageFinished(() => {
this.canGoBack = this.webviewController.accessBackward()
})
Button('返回')
.onClick(() => {
if (this.canGoBack) {
this.webviewController.accessBackward()
}
})
}
.width('100%')
}
}