调取后台url地址点击跳转新页面

利用uniapp框架
1.代码参考:https://gitee.com/hnjihai/jshop_mall/tree/master/uni-app
打开config文件夹找到common.js在其中我们可以看到
jumpTohttp()这个方法跳转外部链接未包含跳转内部链接,在后面的页面点击事件中会用到这个方法。

function jumpTohttp(url) {
	var str=url.substring(0,4);
	console.log(str);
	 let reg=new RegExp('&','g')//g代表全部
	 let newMsg=url.replace(reg,'-');
	var str1 = url.replace('&', '-');
	if(str==='http'){
		console.log(111);
		console.log(url);
		uni.navigateTo({
			url: '/pages/detail/webView?src='+newMsg,
			animationType: 'pop-in',
			animationDuration: 300
		})
	}else{
		uni.navigateTo({
			url: url,
			animationType: 'pop-in',
			animationDuration: 300
		})
	}
}

2.在这段代码中我们会发现有’/pages/detail/webView?src='这个路径,这个页面是用来传递网址的,我们需要在pages下新建detail目录并建立webView文件,文件内容如下:

<template>
	<view class="content">
		<web-view :src="src"></web-view>
	</view>
</template>

<script>

	export default {
		components: {
				
		},
		data() {
			return {
				src:''
			};
		},
		onLoad(options){
			this.src = options.src;
		}
	}
</script>

<style lang="scss">
	
</style>

3.在需要点击发生页面跳转的标签中写一个点击事件的绑定@click(其中我这里用到了列表循环)
引用common.js中的jumpTohttp()方法

<view  v-for="(item, index)  in list2" :key="index"  class="ul">
        <view class="image2"  @click="$common.jumpTohttp(item.link)">
          <image :src="item.banner_path" style="width: 90rpx; height: 80rpx;" ></image>
        </view>
        <view class="text2">{{item.name}}</view>
      </view>
  • 1
    点赞
  • 1
    收藏
    觉得还不错? 一键收藏
  • 0
    评论
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

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

抵扣说明:

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

余额充值