本文主要是介绍Android WebView加载 Vue 项目,希望对大家解决编程问题提供一定的参考价值,需要的开发者们随着小编来一起学习吧!
1.允许 vue端使用 localStorage存储
需要在 android webview 中作如下设置
myWebView.setDefaultHandler(new DefaultHandler());myWebView.getSettings().setJavaScriptCanOpenWindowsAutomatically(true);//localStorage 允许存储myWebView.getSettings().setDomStorageEnabled(true);myWebView.getSettings().setAppCacheMaxSize(1024*1024*8);//存储的最大容量String appCachePath = getApplicationContext().getCacheDir().getAbsolutePath();myWebView.getSettings().setAppCachePath(appCachePath);myWebView.getSettings().setAllowFileAccess(true);myWebView.getSettings().setAppCacheEnabled(true);myWebView.getSettings().setJavaScriptEnabled(true);myWebView.getSettings().setJavaScriptCanOpenWindowsAutomatically(true); myWebView.loadUrl("http://10.18.31.12:8081/?areaCode=620000&areaName=甘肃省"); 2.向vue端传递参数
android 端webView 拼接参数
myWebView.loadUrl("http://10.18.31.12:8081/?areaCode=620000&areaName=甘肃省");
vue首页面接收参数并存储到 localStorage
created(){
var params = {};
location.search.substr(1).split('&').forEach( function(item){
var s = item.split('=');
params[s[0]]=s[1];
});
localStorage.setItem('areaCode',params.areaCode);
localStorage.setItem('areaName',params.areaName);
}
这篇关于Android WebView加载 Vue 项目的文章就介绍到这儿,希望我们推荐的文章对编程师们有所帮助!