因为专注
所以专业

在 HBuilder X 中将现有网页封装为 APP的方法

✅ 方法一:直接使用 <web-view> 组件加载外部网址

适合直接将已有网站打包成 App,无需改动原网页。

修改 index.vue 为以下代码:

vue

<template>
    <web-view src="https://你的网站地址.com"></web-view>
</template>

<script>
export default {
    data() {
        return {}
    }
}
</script>

<style>
/* 可以清空样式,或设置web-view全屏 */
page {
    height: 100%;
}
web-view {
    width: 100%;
    height: 100%;
}
</style>

✅ 方法二:加载本地 HTML 文件

如果你有一个本地打包好的网页(HTML、CSS、JS 文件),可以放在 static 目录下,然后通过 web-view 加载。

假设你的网页入口是 static/www/index.html

vue

<template>
    <web-view src="/static/www/index.html"></web-view>
</template>

<script>
export default {
    data() {
        return {}
    }
}
</script>

<style>
page, web-view {
    width: 100%;
    height: 100%;
}
</style>

✅ 方法三:使用 manifest.json 配置启动页为网页

你还可以直接在 manifest.json 中配置启动页为网页,这样连 index.vue 都不用写。

在 manifest.json 中添加:

json

{
    "name": "你的App名称",
    "appid": "",
    "description": "",
    "versionName": "1.0.0",
    "versionCode": "100",
    "transformPx": false,
    "app-plus": {
        "launchwebview": {
            "id": "1",
            "url": "https://你的网站地址.com"
        }
    }
}

✅ 修改后的项目结构建议:

text

Tiny Talk/
├── pages/
│   └── index/
│       └── index.vue   ← 替换为上述web-view代码
├── static/
│   └── (可放本地网页文件)
├── unpackage/
├── App.vue
├── index.html
├── main.js
└── manifest.json

✅ 打包步骤:

  1. 在 HBuilder X 中打开项目

  2. 修改 index.vue 为以上任一代码

  3. 运行 → 发行 → 原生 App-云打包

  4. 选择 Android 或 iOS 平台,填写证书信息

  5. 等待云打包完成,下载安装包


如果只是想快速将网页转为 App,推荐使用 方法一,简单直接,无需改动网页代码。

 

 

 

我测试的案例正常:

<template>
<web-view src=”https://english.98pic.com/”></web-view>
</template>

<script>
export default {
data() {
return {}
}
}
</script>

<style>
page, web-view {
width: 100%;
height: 100%;
}
</style>

 

赞(0)
分享到: 更多 (0)

相关推荐

  • 暂无文章

评论 抢沙发

  • 昵称 (必填)
  • 邮箱 (必填)
  • 网址