利用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>