Skip to content
体验新版
项目
组织
正在加载...
登录
切换导航
打开侧边栏
Accustomed_
hello uni-app x
提交
daadcdcb
H
hello uni-app x
项目概览
Accustomed_
/
hello uni-app x
与 Fork 源项目一致
Fork自
DCloud / hello uni-app x
通知
1
Star
0
Fork
0
代码
文件
提交
分支
Tags
贡献者
分支图
Diff
Issue
0
列表
看板
标记
里程碑
合并请求
0
DevOps
流水线
流水线任务
计划
Wiki
0
Wiki
分析
仓库
DevOps
项目成员
Pages
H
hello uni-app x
项目概览
项目概览
详情
发布
仓库
仓库
文件
提交
分支
标签
贡献者
分支图
比较
Issue
0
Issue
0
列表
看板
标记
里程碑
合并请求
0
合并请求
0
Pages
DevOps
DevOps
流水线
流水线任务
计划
分析
分析
仓库分析
DevOps
Wiki
0
Wiki
成员
成员
收起侧边栏
关闭侧边栏
动态
分支图
创建新Issue
流水线任务
提交
Issue看板
提交
daadcdcb
编写于
6月 30, 2023
作者:
DCloud-yinjiacheng
浏览文件
操作
浏览文件
下载
电子邮件补丁
差异文件
新增web-view示例
上级
223f14e3
变更
5
显示空白变更内容
内联
并排
Showing
5 changed file
with
319 addition
and
2 deletion
+319
-2
hybrid/html/local.html
hybrid/html/local.html
+112
-0
pages.json
pages.json
+12
-0
pages/component/web-view-local/web-view-local.uvue
pages/component/web-view-local/web-view-local.uvue
+94
-0
pages/component/web-view/web-view.uvue
pages/component/web-view/web-view.uvue
+99
-0
pages/tabBar/component/component.uvue
pages/tabBar/component/component.uvue
+2
-2
未找到文件。
hybrid/html/local.html
0 → 100644
浏览文件 @
daadcdcb
<!DOCTYPE html>
<html>
<head>
<meta
charset=
"utf-8"
/>
<meta
name=
"viewport"
content=
"width=device-width, initial-scale=1"
>
<title>
本地网页
</title>
<style
type=
"text/css"
>
.btn
{
display
:
block
;
margin
:
20px
auto
;
padding
:
5px
;
background-color
:
#007aff
;
border
:
0
;
color
:
#ffffff
;
height
:
40px
;
width
:
200px
;
}
.btn-red
{
background-color
:
#dd524d
;
}
.btn-yellow
{
background-color
:
#f0ad4e
;
}
.desc
{
padding
:
10px
;
color
:
#999999
;
}
</style>
</head>
<body>
<p
class=
"desc"
>
web-view 组件加载本地 html 示例,仅在 App 环境下生效。点击下列按钮,跳转至其它页面。
</p>
<div
class=
"btn-list"
>
<button
class=
"btn"
type=
"button"
data-action=
"navigateTo"
>
navigateTo
</button>
<button
class=
"btn"
type=
"button"
data-action=
"redirectTo"
>
redirectTo
</button>
<button
class=
"btn"
type=
"button"
data-action=
"navigateBack"
>
navigateBack
</button>
<button
class=
"btn"
type=
"button"
data-action=
"reLaunch"
>
reLaunch
</button>
<button
class=
"btn"
type=
"button"
data-action=
"switchTab"
>
switchTab
</button>
</div>
<p
class=
"desc"
>
网页向应用发送消息。注意:小程序端应用会在此页面后退时接收到消息。
</p>
<div
class=
"btn-list"
>
<button
class=
"btn btn-red"
type=
"button"
id=
"postMessage"
>
postMessage
</button>
</div>
<!-- uni 的 SDK -->
<script
type=
"text/javascript"
src=
"https://unpkg.com/@dcloudio/uni-webview-js@0.0.1/index.js"
></script>
<script
type=
"text/javascript"
>
// document.addEventListener('UniAppJSBridgeReady', function() {
document
.
querySelector
(
'
.btn-list
'
).
addEventListener
(
'
click
'
,
function
(
evt
)
{
var
target
=
evt
.
target
;
if
(
target
.
tagName
===
'
BUTTON
'
)
{
var
action
=
target
.
getAttribute
(
'
data-action
'
);
switch
(
action
)
{
case
'
switchTab
'
:
// uni.switchTab({
// url: '/pages/tabBar/API/API'
// });
window
.
__uniapp_x_
.
postMessage
(
JSON
.
stringify
({
data
:
{
action
:
'
switchTab
'
,
url
:
'
/pages/tabBar/API/API
'
}
}));
break
;
case
'
reLaunch
'
:
// uni.reLaunch({
// url: '/pages/tabBar/API/API'
// });
window
.
__uniapp_x_
.
postMessage
(
JSON
.
stringify
({
data
:
{
action
:
'
reLaunch
'
,
url
:
'
/pages/tabBar/API/API
'
}
}));
break
;
case
'
navigateBack
'
:
// uni.navigateBack({
// delta: 1
// });
window
.
__uniapp_x_
.
postMessage
(
JSON
.
stringify
({
data
:
{
action
:
'
navigateBack
'
,
delta
:
1
}
}));
break
;
default
:
// uni[action]({
// url: '/pages/component/button/button'
// });
window
.
__uniapp_x_
.
postMessage
(
JSON
.
stringify
({
data
:
{
action
:
action
,
url
:
'
/pages/component/button/button
'
}
}));
break
;
}
}
})
// });
document
.
querySelector
(
"
#postMessage
"
).
addEventListener
(
'
click
'
,
function
()
{
window
.
__uniapp_x_
.
postMessage
(
JSON
.
stringify
({
data
:
{
action
:
'
message
'
}
}))
})
</script>
</body>
</html>
\ No newline at end of file
pages.json
浏览文件 @
daadcdcb
...
...
@@ -78,6 +78,18 @@
"navigationBarTitleText"
:
"image"
}
},
{
"path"
:
"pages/component/web-view/web-view"
,
"style"
:
{
"navigationBarTitleText"
:
"web-view"
}
},
{
"path"
:
"pages/component/web-view-local/web-view-local"
,
"style"
:
{
"navigationBarTitleText"
:
"web-view-local"
}
},
{
"path"
:
"pages/tabBar/API/API"
,
"style"
:
{
...
...
pages/component/web-view-local/web-view-local.uvue
0 → 100644
浏览文件 @
daadcdcb
<template>
<view class="uni-flex-item">
<web-view ref="web-view" class="uni-flex-item" src="/hybrid/html/local.html" @onPostMessage="onPostMessage"
@error="error" @loading="loading" @loaded="loaded">
</web-view>
<view class="uni-btn-v">
<button type="primary" @click="back">后退</button>
</view>
<view class="uni-btn-v">
<button type="primary" @click="forward">前进</button>
</view>
<view class="uni-btn-v">
<button type="primary" @click="reload">重新加载</button>
</view>
<view class="uni-btn-v">
<button type="primary" @click="stop">停止加载</button>
</view>
</view>
</template>
<script>
import JSONObject from 'com.alibaba.fastjson.JSONObject';
export default {
data() {
return {
}
},
methods: {
back() {
(this.$refs['web-view'] as IWebViewNode).back();
},
forward() {
(this.$refs['web-view'] as IWebViewNode).forward();
},
reload() {
(this.$refs['web-view'] as IWebViewNode).reload();
},
stop() {
(this.$refs['web-view'] as IWebViewNode).stop();
},
onPostMessage(event: WebViewPostMessageEvent) {
console.log(JSON.stringify(event.detail));
const data = event.detail.data as JSONObject;
switch (data['action']) {
case 'navigateTo':
uni.navigateTo({
url: data['url'] as string
});
break;
case 'redirectTo':
uni.redirectTo({
url: data['url'] as string
});
break;
case 'switchTab':
uni.switchTab({
url: data['url'] as string
});
break;
case 'reLaunch':
uni.reLaunch({
url: data['url'] as string
});
break;
case 'navigateBack':
uni.navigateBack({
delta: data['delta'] as number
});
break;
default:
uni.showModal({
content: JSON.stringify(event.detail),
showCancel: false
});
break;
}
},
error(event: WebViewErrorEvent) {
console.log(JSON.stringify(event.detail));
},
loading(event: WebViewLoadingEvent) {
console.log(JSON.stringify(event.type));
},
loaded(event: WebViewLoadedEvent) {
console.log(JSON.stringify(event.type));
}
}
}
</script>
<style>
</style>
\ No newline at end of file
pages/component/web-view/web-view.uvue
0 → 100644
浏览文件 @
daadcdcb
<template>
<view class="uni-flex-item">
<web-view ref="web-view" class="uni-flex-item" :src="src" :webview-styles="webview_styles"
@onPostMessage="onPostMessage" @error="error" @loading="loading" @loaded="loaded">
</web-view>
<view class="uni-btn-v">
<button type="primary" @click="back">后退</button>
</view>
<view class="uni-btn-v">
<button type="primary" @click="forward">前进</button>
</view>
<view class="uni-btn-v">
<button type="primary" @click="reload">重新加载</button>
</view>
<view class="uni-btn-v">
<button type="primary" @click="stop">停止加载</button>
</view>
</view>
</template>
<script>
import JSONObject from 'com.alibaba.fastjson.JSONObject';
export default {
data() {
return {
src: 'https://uniapp.dcloud.io/static/web-view.html',
webview_styles: {
progress: {
color: '#FF3333'
}
} as UTSJSONObject
}
},
methods: {
back() {
(this.$refs['web-view'] as IWebViewNode).back();
},
forward() {
(this.$refs['web-view'] as IWebViewNode).forward();
},
reload() {
(this.$refs['web-view'] as IWebViewNode).reload();
},
stop() {
(this.$refs['web-view'] as IWebViewNode).stop();
},
onPostMessage(event: WebViewPostMessageEvent) {
console.log(JSON.stringify(event.detail));
const data = event.detail.data as JSONObject;
switch (data['action']) {
case 'navigateTo':
uni.navigateTo({
url: data['url'] as string
});
break;
case 'redirectTo':
uni.redirectTo({
url: data['url'] as string
});
break;
case 'switchTab':
uni.switchTab({
url: data['url'] as string
});
break;
case 'reLaunch':
uni.reLaunch({
url: data['url'] as string
});
break;
case 'navigateBack':
uni.navigateBack({
delta: data['delta'] as number
});
break;
default:
uni.showModal({
content: JSON.stringify(event.detail),
showCancel: false
});
break;
}
},
error(event: WebViewErrorEvent) {
console.log(JSON.stringify(event.detail));
},
loading(event: WebViewLoadingEvent) {
console.log(JSON.stringify(event.type));
},
loaded(event: WebViewLoadedEvent) {
console.log(JSON.stringify(event.type));
}
}
}
</script>
<style>
</style>
\ No newline at end of file
pages/tabBar/component/component.uvue
浏览文件 @
daadcdcb
...
...
@@ -190,12 +190,12 @@
pages: [
{
name: '网络网页',
enable:
fals
e,
enable:
tru
e,
url: '/pages/component/web-view/web-view'
},
{
name: '本地网页',
enable:
fals
e,
enable:
tru
e,
url: '/pages/component/web-view-local/web-view-local'
}
] as Page[]
...
...
编辑
预览
Markdown
is supported
0%
请重试
或
添加新附件
.
添加附件
取消
You are about to add
0
people
to the discussion. Proceed with caution.
先完成此消息的编辑!
取消
想要评论请
注册
或
登录