zhangzengfei
2021-09-16 38430ddb8612fce15a2f1c940f9bd57d4da3e70b
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
<template>
    <view >
        <web-view style="top:44rpx;" :webview-styles="webviewStyles" src="https://ditu.amap.com/search?id=B000A6AF30&city=110108&geoobj=110.234084%7C32.218361%7C110.24359%7C32.223114&query_type=IDQ&query=%E5%8C%97%E4%BA%AC%E5%B8%82%E8%82%B2%E8%8B%B1%E4%B8%AD%E5%AD%A6"></web-view>
    </view>
</template>
 
<script>
    var wv;  
    var pageUrl = 'https://ditu.amap.com/search?id=B000A6AF30&city=110108&geoobj=110.234084%7C32.218361%7C110.24359%7C32.223114&query_type=IDQ&query=%E5%8C%97%E4%BA%AC%E5%B8%82%E8%82%B2%E8%8B%B1%E4%B8%AD%E5%AD%A6';
    //var pageUrl = 'https://www.amap.com/search?id=B000A6AF30&city=110108&geoobj=112.467616%7C29.123802%7C119.790531%7C32.648103&query_type=IDQ&query=%E5%8C%97%E4%BA%AC%E5%B8%82%E8%82%B2%E8%8B%B1%E4%B8%AD%E5%AD%A6&zoom=7.41';
    export default {
        data() {
            return {
                webviewStyles:{
                    progress: {
                        color: '#00ff7f',
                        top: '20px'
                    }
                }
            }
        },
        onReady(){
            // #ifdef APP-PLUS
            var currentWebview = this.$scope.$getAppWebview() //此对象相当于html5plus里的plus.webview.currentWebview()。在uni-app里vue页面直接使用plus.webview.currentWebview()无效,非v3编译模式使用this.$mp.page.$getAppWebview()
            console.log(currentWebview);
            setTimeout(function() {
                wv = currentWebview.children()[0]
                wv.setStyle({top:22, height:uni.getSystemInfoSync().windowHeight-22})
                //wv.setStyle({top:uni.getSystemInfoSync().statusBarHeight+44});
            }, 1000); //如果是页面初始化调用时,需要延时一下
            // #endif
        },
        // onLoad() {
        //     // #ifdef APP-PLUS
        //     wv = plus.webview.create("","custom-webview",{
        //         plusrequire:"none", //禁止远程网页使用plus的API,有些使用mui制作的网页可能会监听plus.key,造成关闭页面混乱,可以通过这种方式禁止
        //         'uni-app': 'none', //不加载uni-app渲染层框架,避免样式冲突
        //         //top:uni.getSystemInfoSync().statusBarHeight+44 //放置在titleNView下方。如果还想在webview上方加个地址栏的什么的,可以继续降低TOP值
        //         top:52, 
        //         height:uni.getSystemInfoSync().windowHeight-52
        //     })
        //     wv.loadURL("https://ditu.amap.com/search?id=B000A6AF30&city=110108&geoobj=110.234084%7C32.218361%7C110.24359%7C32.223114&query_type=IDQ&query=%E5%8C%97%E4%BA%AC%E5%B8%82%E8%82%B2%E8%8B%B1%E4%B8%AD%E5%AD%A6&zoom=17")
        //     var currentWebview = this.$mp.page.$getAppWebview() //获取当前页面的webview对象
        //     currentWebview.append(wv);
        //     setTimeout(function() {
        //         console.log(wv.getStyle())
                
        //     }, 1000);//如果是首页的onload调用时需要延时一下,二级页面无需延时,可直接获取
        //     // #endif
        // },
        
        methods: {
            
        }
    }
</script>
 
<style lang="scss" scoped>
    uni-page-wrapper,uni-page-body{
        height: 100%;
        padding-top:44rpx;
    }
    .common_header{
        background-color: #fff!important;
    }
    .gap{
        height:44rpx;
    }
</style>