uniapp跳转H5外部链接

不携带参数的跳转外部链接请求

<view class="yes" @click="goh5">{{'未完成':'已完成'}}</view>

this.content.contractUrl为后端传输的url地址

 goh5() {
    if (this.content.signStatus == 1) {
   const url = this.content.contractUrl
   uni.navigateTo({
     url: '/pages/web/web?url=' + encodeURIComponent(JSON.stringify(url))
         })
   } else {
       const hurl = this.content.wxOfficialAccountUrl
      uni.navigateTo({
       url: '/pages/web/web?hurl=' + encodeURIComponent(JSON.stringify(hurl))
          })
          }
       }
<template>
	<view class="box">
		<web-view v-if="URL" :src="URL"></web-view>
	</view>
</template>

<script>
	export default {
		data() {
			return {
				URL: undefined,
			}
		},
		onLoad(e) {
			// 传入需要跳转的链接 使用web-view标签进行跳转
				this.URL = JSON.parse(decodeURIComponent(e.url))
		},
		methods: {
			
			}
		},
	}
</script>

携带参数的跳转外部链接请求

若传递参数中含有=,?,&等特殊字符 无法正常传递参数 则需要进行编码解码 传递时使用encodeURIComponent() 接收时使用decodeURIComponent()

//传递处理
let url = 'https://xxxxx.xxxx.com/mini/api/?id=2222&key=kkkkk'
my.navigateTo({
	url: `/pages/Web/Web?url=${encodeURIComponent(JSON.stringify(url))}`
})
 
//页面接收
onLoad(options) {
	console.log('Url---', options, decodeURIComponent(JSON.parse(options.url)));
	this.setData({
		url: decodeURIComponent(JSON.parse(options.url))
	})
},

 

评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值