uniapp使用web-view跳转外部链接
生活随笔
收集整理的這篇文章主要介紹了
uniapp使用web-view跳转外部链接
小編覺得挺不錯(cuò)的,現(xiàn)在分享給大家,幫大家做個(gè)參考.
1.創(chuàng)建webView跳轉(zhuǎn)公用文件(home是調(diào)用處);
<template> <web-view :src="url"></web-view> </template><script> export default {name: "index",data(){return{url:''}},onLoad(val){//動(dòng)態(tài)獲取的urlthis.url=decodeURIComponent(val.url)} } </script><style scoped> </style>2.在使用頁(yè)面調(diào)用webview跳轉(zhuǎn)(encodeURIComponent() 函數(shù)可把字符串作為 URI 組件進(jìn)行編碼。敲黑板~重點(diǎn))
//頁(yè)面調(diào)用處 <uni-grid-item @tap="queryCorpInfo"><image class="image" src="../../../static/img/home/corpInfoImage.png" mode="aspectFill"></image><text class="text">跳轉(zhuǎn)外部連接</text> </uni-grid-item>//執(zhí)行方法 queryCorpInfo(){let url = this.baseHtmlUrl+'qhbs_h5_v1/pages/corpInfo/corpInfo.html'var typefrom = 'wechat';url = encodeURIComponent(url + '?typefrom=${typefrom}');uni.navigateTo({url: '../../webview/index?url='+ url});}?
3.html中獲取攜帶的參數(shù)。
//獲取地址欄參數(shù),name:參數(shù)名稱 function getUrlParms (name) {let url = window.location.href;//獲取請(qǐng)求進(jìn)來的完整urllet tstr = url.substring(url.indexOf('?') + 1).split('&');//先截取url的?后面的參數(shù)部分,在根據(jù)&分割成參數(shù)數(shù)組let result = {};tstr.forEach((item) => {let res = item.split('=');//res為type,my-component1.vue。 ?res[0]為type,res[1為]my-component1.vueresult[res[0]] = res[1];//構(gòu)造成鍵值對(duì)形式 res[0]為鍵,res[1]為值 例:type: "my-component1.vue"?})return result[name];//通過鍵取值 }var type = getUrlParms("type");//調(diào)用函數(shù)即可?
?
?
?
?
總結(jié)
以上是生活随笔為你收集整理的uniapp使用web-view跳转外部链接的全部?jī)?nèi)容,希望文章能夠幫你解決所遇到的問題。
- 上一篇: 求助,Python安装了Anaconda
- 下一篇: Excel删除重复数据java_合并Ex