HarmonyOS 本地html传参问题

在项目resources/rawfile目录下存放index.html文件,通过let path = $rawfile('index.html')这种方式如何在uri后面拼接参数?例如index.html?num=1&page=1这种形式。

HarmonyOS
2024-11-05 11:32:47
浏览
收藏 0
回答 1
回答 1
按赞同
/
按时间
superinsect

可以参考以下demo:

//应用侧代码 
import web_webview from '@ohos.web.webview' 
@Entry 
@Component 
struct WebComponent { 
  controller: web_webview.WebviewController = new web_webview.WebviewController() 
  build() { 
    Column() { 
      Web({ src: 'resource://rawfile/index.html?key=value', controller: this.controller }) 
        .javaScriptAccess(true) 
        .domStorageAccess(true) 
    } 
  } 
}
//H5侧代码 
index.html: 
<!DOCTYPE html> 
<html> 
<head> 
<title>Parameter-based HTML</title> 
</head> 
<body> 
<h1>Welcome!</h1> 
<p id="params"></p> 
<script> 
function getParams() { 
var params = {}; 
window.location.search.substring(1).split('&').forEach(function(param) { 
var pair = param.split('='); 
params[pair[0]] = decodeURIComponent(pair[1]); 
}); 
return params; 
} 
document.getElementById('params').innerHTML = JSON.stringify(getParams()); 
</script> 
</body> 
</html>
  • 1.
  • 2.
  • 3.
  • 4.
  • 5.
  • 6.
  • 7.
  • 8.
  • 9.
  • 10.
  • 11.
  • 12.
  • 13.
  • 14.
  • 15.
  • 16.
  • 17.
  • 18.
  • 19.
  • 20.
  • 21.
  • 22.
  • 23.
  • 24.
  • 25.
  • 26.
  • 27.
  • 28.
  • 29.
  • 30.
  • 31.
  • 32.
  • 33.
  • 34.
  • 35.
  • 36.
  • 37.
分享
微博
QQ
微信
回复
2024-11-05 15:20:44
相关问题
HarmonyOS 页面问题
841浏览 • 1回复 待解决
HarmonyOS 参数问题
508浏览 • 1回复 待解决
HarmonyOS Navigation问题
442浏览 • 1回复 待解决
JS跳转Java问题
5303浏览 • 1回复 待解决
HarmonyOS HTTP使用Map问题
507浏览 • 1回复 待解决
HarmonyOS @Builder Params问题
362浏览 • 1回复 待解决
HarmonyOS router获取问题
889浏览 • 1回复 待解决
HarmonyOS POST请求
635浏览 • 1回复 待解决
HarmonyOS 自动化测试问题
464浏览 • 1回复 待解决
跨设备启动FA问题
8725浏览 • 1回复 待解决
HarmonyOS webview加载本地html问题
1255浏览 • 1回复 待解决
HarmonyOS 页面导航跳转回调问题
1734浏览 • 0回复 待解决
HarmonyOS 页面间如何
1386浏览 • 1回复 待解决
路由如何接?可否给个案例?
3657浏览 • 1回复 待解决
HarmonyOS router跳转返回如何
331浏览 • 1回复 待解决
HarmonyOS 调用flutter页面并
316浏览 • 1回复 待解决
网络请求-GET请求
1095浏览 • 1回复 待解决
烧录问题,我有一点疑惑
8114浏览 • 4回复 待解决
ArkTS 网络请求 接口动态
949浏览 • 1回复 待解决