注意:目前通過webview跳轉到其他網址支持:
1、與微信小程序綁定的微信公眾號文章地址;
2、在微信小程序后台配置好業務域名的地址。
1、新建一個只有webview組件的頁面
linkOthers:
<template> <view> <view> <!-- url為要跳轉外鏈的地址--> <web-view :src="url"> </web-view> </view> </view> </template> <script> export default { data() { return { url:"" } }, onLoad(val) { this.url = decodeURIComponent(val.url); // 設置當前的title 如果外鏈中有的話將被覆蓋 if(this.isNotEmpty(val.title)){ this.setTitle(val.title); } }, methods: { isNotEmpty(obj) { if (typeof obj == undefined || obj == null || obj == "" || obj == "undefined" || obj.length == 0) { return false; } else { return true; } }, // 設置title setTitle(title) { uni.setNavigationBarTitle({ title: title }) }, } } </script>
二、觸發跳轉
<template> <view> <button @click="linkOthers()"></button> </view> </template> <script> export default { methods: { linkOthers(){ // 此處填寫你要跳轉的綁定公眾號文章的鏈接地址或者已經在小程序后台配置好業務域名的地址 var url = "https://www.baidu.com"; uni.navigateTo({ // 此處的鏈接為小程序上面新建的webview頁面路徑,參數url為要跳轉外鏈的地址 url:"/pages/common/linkOthers/linkOthers?url=" + encodeURIComponent(url) }); } } } </script>
來源:https://blog.csdn.net/weixin_44379204/article/details/106648979?utm_medium=distribute.pc_relevant.none-task-blog-BlogCommendFromBaidu-1.control&depth_1-utm_source=distribute.pc_relevant.none-task-blog-BlogCommendFromBaidu-1.control