中国优质的IT技术网站
专业IT技术创作平台
IT职业在线教育平台
如何为网页设置单个Cookie的值。
微信扫码分享
import web_webview from '@ohos.web.webview'; import business_error from '@ohos.base'; @Entry @Component struct Index { webviewController: web_webview.WebviewController = new web_webview.WebviewController(); build() { Column() { Web({ src: "https://www.example.com", controller: this.webviewController }) Button('配置Cookie') .onClick(() => { try { //configCookieSync设置cookie web_webview.WebCookieManager.configCookieSync('https://www.example.com', 'value=test'); } catch (error) { let e: business_error.BusinessError = error as business_error.BusinessError; console.error(`ErrorCode: ${e.code}, Message: ${e.message}`); } }) } .width('100%') .height('100%') .justifyContent(FlexAlign.Center) } }