Skip to content
体验新版
项目
组织
正在加载...
登录
切换导航
打开侧边栏
DCloud
hello uni-app x
提交
8b066d03
H
hello uni-app x
项目概览
DCloud
/
hello uni-app x
通知
5995
Star
90
Fork
162
代码
文件
提交
分支
Tags
贡献者
分支图
Diff
Issue
18
列表
看板
标记
里程碑
合并请求
1
DevOps
流水线
流水线任务
计划
Wiki
0
Wiki
分析
仓库
DevOps
项目成员
Pages
H
hello uni-app x
项目概览
项目概览
详情
发布
仓库
仓库
文件
提交
分支
标签
贡献者
分支图
比较
Issue
18
Issue
18
列表
看板
标记
里程碑
合并请求
1
合并请求
1
Pages
DevOps
DevOps
流水线
流水线任务
计划
分析
分析
仓库分析
DevOps
Wiki
0
Wiki
成员
成员
收起侧边栏
关闭侧边栏
动态
分支图
创建新Issue
流水线任务
提交
Issue看板
提交
8b066d03
编写于
7月 06, 2023
作者:
DCloud-yinjiacheng
浏览文件
操作
浏览文件
下载
电子邮件补丁
差异文件
更新web-view示例
上级
04977efd
变更
2
隐藏空白更改
内联
并排
Showing
2 changed file
with
39 addition
and
79 deletion
+39
-79
pages/component/web-view-local/web-view-local.uvue
pages/component/web-view-local/web-view-local.uvue
+4
-30
pages/component/web-view/web-view.uvue
pages/component/web-view/web-view.uvue
+35
-49
未找到文件。
pages/component/web-view-local/web-view-local.uvue
浏览文件 @
8b066d03
...
...
@@ -3,20 +3,6 @@
<web-view ref="web-view" class="uni-flex-item" src="/hybrid/html/local.html" @message="message" @error="error"
@loading="loading" @loaded="loaded">
</web-view>
<view class="uni-padding-wrap uni-common-mt">
<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>
</view>
</template>
...
...
@@ -28,19 +14,7 @@
}
},
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();
},
message(event: WebViewMessageEvent) {
message(event : WebViewMessageEvent) {
console.log(JSON.stringify(event.detail));
const data = event.detail.data;
if (data == null) return;
...
...
@@ -78,13 +52,13 @@
break;
}
},
error(event: WebViewErrorEvent) {
error(event
: WebViewErrorEvent) {
console.log(JSON.stringify(event.detail));
},
loading(event: WebViewLoadingEvent) {
loading(event
: WebViewLoadingEvent) {
console.log(JSON.stringify(event.type));
},
loaded(event: WebViewLoadedEvent) {
loaded(event
: WebViewLoadedEvent) {
console.log(JSON.stringify(event.type));
}
}
...
...
pages/component/web-view/web-view.uvue
浏览文件 @
8b066d03
...
...
@@ -4,17 +4,24 @@
@error="error" @loading="loading" @loaded="loaded">
</web-view>
<view class="uni-padding-wrap uni-common-mt">
<view class="uni-
btn
-v">
<
button type="primary" @click="back">后退</button
>
<view class="uni-
input
-v">
<
input class="uni-input" confirmType="go" placeholder="输入网址跳转" @confirm="confirm" /
>
</view>
<view class="uni-btn-v">
<button type="primary" @click="forward">前进</button>
<view class="uni-row uni-btn-v">
<view class="uni-flex-item">
<button type="primary" @click="back">后退</button>
</view>
<view class="uni-btn-ml uni-flex-item">
<button type="primary" @click="forward">前进</button>
</view>
</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 class="uni-row uni-btn-v">
<view class="uni-flex-item">
<button type="primary" @click="reload">重新加载</button>
</view>
<view class="uni-btn-ml uni-flex-item">
<button type="primary" @click="stop">停止加载</button>
</view>
</view>
</view>
</view>
...
...
@@ -24,7 +31,7 @@
export default {
data() {
return {
src: 'https://
uniapp.dcloud.io/static/web-view.html
',
src: 'https://
www.baidu.com
',
webview_styles: {
progress: {
color: '#FF3333'
...
...
@@ -45,57 +52,36 @@
stop() {
(this.$refs['web-view'] as IWebViewNode).stop();
},
message(event: WebViewMessageEvent) {
message(event
: WebViewMessageEvent) {
console.log(JSON.stringify(event.detail));
const data = event.detail.data;
if (data == null) return;
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) {
error(event
: WebViewErrorEvent) {
console.log(JSON.stringify(event.detail));
},
loading(event: WebViewLoadingEvent) {
loading(event
: WebViewLoadingEvent) {
console.log(JSON.stringify(event.type));
},
loaded(event: WebViewLoadedEvent) {
loaded(event
: WebViewLoadedEvent) {
console.log(JSON.stringify(event.type));
},
confirm(event : InputConfirmEvent) {
console.log(event.detail.value);
let url = event.detail.value;
if (!url.startsWith('https://') && !url.startsWith('http://')) {
url = 'https://' + url;
}
this.src = url;
}
}
}
</script>
<style>
.uni-input-v {
padding: 10rpx 0;
}
.uni-btn-ml {
margin-left: 10rpx;
}
</style>
\ No newline at end of file
编辑
预览
Markdown
is supported
0%
请重试
或
添加新附件
.
添加附件
取消
You are about to add
0
people
to the discussion. Proceed with caution.
先完成此消息的编辑!
取消
想要评论请
注册
或
登录