1.創建一個空的文件
2.在文件夾里放置web-view
<view> <web-view :src="url" :progress="false"> </web-view> </view>
3.在js里接收傳遞過來的鏈接
<script>
export default {
data() {
return {
url: ''
};
},
onLoad(val) {
this.url = decodeURIComponent(val.url) //解碼網址
},
}
</script>
4.在要跳轉的頁面里的標簽添加點擊方法
<view class="banner" @tap="tonewurl"> </view>
5.定義點擊方法
// 跳轉外部鏈接
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(':')[0];
let a = notS.indexOf('s') > -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}&utoken=${utoken}&unionid=${unionid}&shopid=${shopId}`);
uni.navigateTo({
url: '../newurl/newurl?url=' + url
});
},
