如何写精华回答,获更多曝光?
发布
根据文档,WebView加载网络链接的时候 可以设置Cookie,代码如下:
Web({ src: "https://www.huawei.com", controller: this.webController })
.onPageEnd(() => {
try {
web_webview.WebCookieManager.configCookieSync("https://www.huawei.com", 'test=1');
} catch (error) {
let e: business_error.BusinessError = error as business_error.BusinessError;
console.error(`ErrorCode: ${e.code}, Message: ${e.message}`);
}
})
但是如果加载本地文件:
Web({ src: $rawfile("index.html"), controller: this.webController })
.onPageEnd(() => {
try {
web_webview.WebCookieManager.configCookieSync("index.html", 'test=1');
} catch (error) {
let e: business_error.BusinessError = error as business_error.BusinessError;
console.error(`ErrorCode: ${e.code}, Message: ${e.message}`);
}
})
这样写不起作用,请问应该如何写?