在上一頁點(diǎn)擊需要跳轉(zhuǎn)到app內(nèi)置的瀏覽器里(app跳h5頁面),uniapp提供了web-view
需要新建頁面,在新頁面里引用web-view,在新頁面里才加上網(wǎng)址(h5)
1,在所需頁面引入
//如果不暫存在本地,會(huì)在瀏覽器上被轉(zhuǎn)譯
uni.setStorageSync('PAYWEBURL', res.data.data.url)//考慮到所傳網(wǎng)址需要轉(zhuǎn)譯嗎(不需要)
// let enUrl = encodeURIComponent(res.data.data.url)//轉(zhuǎn)譯
uni.navigateTo({
//url: '/pages/cashier/payapp'+enUrl//需要在調(diào)轉(zhuǎn)頁里轉(zhuǎn)譯回去
url: '/pages/cashier/payapp'//如果不需要轉(zhuǎn)譯先把網(wǎng)址暫存在本地,在跳轉(zhuǎn)頁面里取出,防止瀏覽器轉(zhuǎn)譯
})
1,在項(xiàng)目里(uni-app)運(yùn)用(子傳父)
<template>
<view>
<web-view @message="getMessage" :src="webViewUrl"></web-view>
</view>
</template>
<script>
export default {
data() {
return {
webViewUrl: ''
}
},
onLoad() {
// this.webViewUrl = decodeURIComponent(options.url)// 傳過來的值是轉(zhuǎn)譯過的,需要轉(zhuǎn)回原值
this.webViewUrl = uni.getStorageSync('PAYWEBURL')//如果是不需要轉(zhuǎn)譯的,直接獲取
console.log(this.webViewUrl)
},
methods: {
getMessage(e) {
console.log('webView傳遞過來的消息',e)
}
}
}
</script>
3,html頁面文章來源:http://www.zghlxwxcb.cn/news/detail-504874.html
https://gitee.com/dcloud/uni-app/raw/dev/dist/uni.webview.1.5.4.js文章來源地址http://www.zghlxwxcb.cn/news/detail-504874.html
<!-- 用于支付結(jié)束后跳轉(zhuǎn)app -->
<!DOCTYPE html>
<html lang="en">
<head>
<meta charset="UTF-8">
<meta http-equiv="X-UA-Compatible" content="IE=edge">
<meta name="viewport" content="width=device-width, initial-scale=1.0">
<title>web-view</title>
//重點(diǎn),一定要引入
<script src="./js/uni.webview.1.5.4.js"></script>
</head>
<body>
</body>
<script>
document.addEventListener('UniAppJSBridgeReady', function() {
uni.getEnv(function(res) {
console.log('當(dāng)前環(huán)境:' + JSON.stringify(res));//判斷當(dāng)前是在網(wǎng)頁還是app還是小程序
})
//在網(wǎng)頁做什么,(跳轉(zhuǎn)到指定頁)
uni.redirectTo({
url:'/pagesOrder/order/list'
})
})
</script>
</html>
到了這里,關(guān)于uni-app web-view的使用的文章就介紹完了。如果您還想了解更多內(nèi)容,請?jiān)谟疑辖撬阉鱐OY模板網(wǎng)以前的文章或繼續(xù)瀏覽下面的相關(guān)文章,希望大家以后多多支持TOY模板網(wǎng)!