作者 “关晓峰”

fix: 优化代码

1 .hbuilderx 1 .hbuilderx
2 unpackage 2 unpackage
3 node_modules 3 node_modules
4 -node_modules  
5 -node_modules  
6 -node_modules  
1 -旌阳市场监管平台 1 +设备乐平台
2 2
3 ## 特别鸣谢 3 ## 特别鸣谢
4 4
1 -<!DOCTYPE html>  
2 -<html>  
3 - <head>  
4 - <meta charset="utf-8" />  
5 - <meta name="viewport" content="width=device-width, initial-scale=1">  
6 - <title>本地网页</title>  
7 - <style type="text/css">  
8 - .btn {  
9 - display: block;  
10 - margin: 20px auto;  
11 - padding: 5px;  
12 - background-color: #007aff;  
13 - border: 0;  
14 - color: #ffffff;  
15 - height: 40px;  
16 - width: 200px;  
17 - }  
18 -  
19 - .btn-red {  
20 - background-color: #dd524d;  
21 - }  
22 -  
23 - .btn-yellow {  
24 - background-color: #f0ad4e;  
25 - }  
26 -  
27 - .desc {  
28 - padding: 10px;  
29 - color: #999999;  
30 - }  
31 - </style>  
32 - </head>  
33 - <body>  
34 - <p class="desc">web-view 组件加载本地 html 示例,仅在 App 环境下生效。点击下列按钮,跳转至其它页面。</p>  
35 - <div class="btn-list">  
36 - <button class="btn" type="button" data-action="navigateTo">navigateTo</button>  
37 - <button class="btn" type="button" data-action="redirectTo">redirectTo</button>  
38 - <button class="btn" type="button" data-action="navigateBack">navigateBack</button>  
39 - <button class="btn" type="button" data-action="reLaunch">reLaunch</button>  
40 - <button class="btn" type="button" data-action="switchTab">switchTab</button>  
41 - </div>  
42 - <p class="desc">网页向应用发送消息。注意:小程序端应用会在此页面后退时接收到消息。</p>  
43 - <div class="btn-list">  
44 - <button class="btn btn-red" type="button" id="postMessage">postMessage</button>  
45 - </div>  
46 - <!-- uni 的 SDK -->  
47 - <script type="text/javascript" src="https://unpkg.com/@dcloudio/uni-webview-js@0.0.1/index.js"></script>  
48 - <script type="text/javascript">  
49 - document.addEventListener('UniAppJSBridgeReady', function() {  
50 - document.querySelector('.btn-list').addEventListener('click', function(evt) {  
51 - var target = evt.target;  
52 - if (target.tagName === 'BUTTON') {  
53 - var action = target.getAttribute('data-action');  
54 - switch (action) {  
55 - case 'switchTab':  
56 - uni.switchTab({  
57 - url: '/pages/tabBar/API/API'  
58 - });  
59 - break;  
60 - case 'reLaunch':  
61 - uni.reLaunch({  
62 - url: '/pages/tabBar/API/API'  
63 - });  
64 - break;  
65 - case 'navigateBack':  
66 - uni.navigateBack({  
67 - delta: 1  
68 - });  
69 - break;  
70 - default:  
71 - uni[action]({  
72 - url: '/pages/component/button/button'  
73 - });  
74 - break;  
75 - }  
76 - }  
77 - });  
78 - document.querySelector("#postMessage").addEventListener('click', function() {  
79 - uni.postMessage({  
80 - data: {  
81 - action: 'message'  
82 - }  
83 - });  
84 - })  
85 - });  
86 - </script>  
87 - </body>  
88 -</html>  
1 { 1 {
2 - "name" : "市场监管", 2 + "name" : "设备乐",
3 "appid" : "__UNI__64CFE40", 3 "appid" : "__UNI__64CFE40",
4 - "description" : "多平台快速开发的UI框架", 4 + "description" : "",
5 "versionName" : "1.0.0", 5 "versionName" : "1.0.0",
6 "versionCode" : 1, 6 "versionCode" : 1,
7 "transformPx" : false, 7 "transformPx" : false,
1 { 1 {
2 - "name": "uView2.0重磅发布,利剑出鞘,一统江湖示例", 2 + "name": "设备乐",
3 "lockfileVersion": 2, 3 "lockfileVersion": 2,
4 "requires": true, 4 "requires": true,
5 "packages": { 5 "packages": {