初始化 Vue3+Vite 前端模板,适配 WebView2 桥接
新增项目基础结构与配置,集成 Vue3、Vite、TypeScript、ESLint 等开发环境。实现主页面、样式、图标组件,封装 http 请求,支持 WebView2 与普通浏览器统一 API 调用,便于与 C# 后端通信。完善类型声明与开发文档。
This commit is contained in:
@@ -8,6 +8,7 @@
|
||||
<h1>WebView2 自定义协议演示</h1>
|
||||
<button id="getUserBtn">获取用户信息</button>
|
||||
<button id="processBtn">处理数据</button>
|
||||
<button id="wBtn">天气数据</button>
|
||||
<pre id="output"></pre>
|
||||
|
||||
<script src="./api.js"></script>
|
||||
@@ -32,6 +33,15 @@
|
||||
}
|
||||
};
|
||||
|
||||
document.getElementById('wBtn').onclick = async () => {
|
||||
try {
|
||||
const result = await window.api.wData('hello world');
|
||||
output.textContent = JSON.stringify(result, null, 2);
|
||||
} catch (err) {
|
||||
output.textContent = `错误: ${err.message}`;
|
||||
}
|
||||
};
|
||||
|
||||
const detectIsWebView2 = () => window.isWebView2 === true || typeof window.invokeCSharpAction === 'function';
|
||||
|
||||
const renderEnvironment = () => {
|
||||
|
||||
Reference in New Issue
Block a user