uni.navigateTo携带参数(网址)跳转页面
问题:
传递参数(http://lt.sapxw.com/H5ErWeiMa/indexH5.aspx?id=290949&ckdh=637695418429358201)给intoInventoryRelativeDetail.vue页面,但是值实际传递了(http://lt.sapxw.com/H5ErWeiMa/indexH5.aspx)并报这个警告[sitemap 索引情况提示] 根据 sitemap 的默认规则,当前页面 [pagesBtnDetail/intoInventoryRelativeDetail/intoInventoryRelativeDetail?url=http%3A%2F%2Flt.sapxw.com%2FH5ErWeiMa%2FindexH5.aspx] 将被索引
解决办法:
使用encodeURIComponent() 函数和decodeURIComponent() 函数
encodeURIComponent() 函数可把字符串作为 URI 组件进行编码。
decodeURIComponent() 函数对 URI 组件进行解码。完美解决!
scanURL(e) {
if (e == '') {
this.showToast('请扫描二维码!')
return false
}
// http://lt.sapxw.com/H5ErWeiMa/indexH5.aspx?id=290949&ckdh=637695418429358201
let url = encodeURIComponent(e);
uni.navigateTo({
url: `/pagesBtnDetail/intoInventoryRelativeDetail/intoInventoryRelativeDetail?url=${url}`
})
},
intoInventoryRelativeDetail.vue
<template>
<view>
<web-view :src="url"></web-view>
</view>
</template>
<script>
export default {
data() {
return {
url: 'http://lt.sapxw.com/H5ErWeiMa/indexH5.aspx?id=290949&ckdh=637695418429358201',
}
},
onLoad(e) {
// 获取传递过来的链接
let url = decodeURIComponent(e.url);
console.log(url)
this.url = url
},
methods: {
}
}
</script>
<style>
</style>
完美解决!