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