就是让你气急败坏 發表於 2019-7-20 12:04:00

在小程序里添加跳转外部链接web-view(使用的是uni-app)

<p>1.创建一个空的文件</p>
<p>2.在文件夹里放置web-view</p>
<div class="cnblogs_Highlighter">
<pre class="brush:javascript;gutter:true;">&lt;view&gt;
        &lt;web-view :src="url" :progress="false"&gt;
        &lt;/web-view&gt;
&lt;/view&gt;
</pre>
</div>
<p>3.在js里接收传递过来的链接</p>
<div class="cnblogs_Highlighter">
<pre class="brush:javascript;gutter:true;">&lt;script&gt;
        export default {
                data() {
                        return {
                                url: ''
                        };
                },
                onLoad(val) {
                        this.url = decodeURIComponent(val.url) //解码网址
                },
        }
&lt;/script&gt;
</pre>
</div>
<p> 4.在要跳转的页面里的标签添加点击方法</p>
<div class="cnblogs_Highlighter">
<pre class="brush:javascript;gutter:true;">&lt;view class="banner" @tap="tonewurl"&gt;
&lt;/view&gt;
</pre>
</div>
<p>  5.定义点击方法</p>
<div class="cnblogs_Highlighter">
<pre class="brush:javascript;gutter:true;">        // 跳转外部链接
                        tonewurl() {
                                let url = this.result.vr_link;//接收返回的数据
                                let shopId = this.result.uniacid;
                                let utoken = uni.getStorageSync('user').utoken;
                                let unionid = uni.getStorageSync('user').unionid;
                                if (!this.getUserStatus()) {
                                        return;
                                }
                                // 判断链接是否为空
                                if (url == null) {
                                        return false;
                                }
                                // 判断链接是否为https
                                let notS = url.split(':');
                                let a = notS.indexOf('s') &gt; -1;
                                if (a == false) {
                                        return false;
                                }
                              //条件编译
                                //#ifdef MP-WEIXIN
                                var typefrom = 'wechat';
                                //#endif
                                //#ifdef MP-BAIDU
                                var typefrom = 'baidu';
                                //#endif
                                //#ifdef MP-ALIPAY
                                var typefrom = 'ali';
                                //#endif
                                //#ifdef APP-PLUS
                                var typefrom = 'APP';
                                //#endif
                            //链接拼接编码网址(同时用模板字符串放置所需要的数据)
                                url = encodeURIComponent(url + `?typefrom=${typefrom}&amp;utoken=${utoken}&amp;unionid=${unionid}&amp;shopid=${shopId}`);
                                uni.navigateTo({
                                        url: '../newurl/newurl?url=' + url
                                });
                        },      
</pre>
</div>
<p>  </p><br><br>
来源:https://www.cnblogs.com/Glant/p/11217270.html
頁: [1]
查看完整版本: 在小程序里添加跳转外部链接web-view(使用的是uni-app)