创建一个新的页面,在该页面中使用web-view组件加载外部URL:pages/web-view/web-view
javascript
<template>
<view>
<uni-list>
<uni-list-item
title="打开外部链接"
@click="openExternalLink"
></uni-list-item>
</uni-list>
</view>
</template>
<script>
export default {
methods: {
openExternalLink() {
window.open('https://super.xiaoxilao.com/', '_blank');
}
}
}
</script>
<style>
/* 你的样式 */
</style>
在我们当前需要点击跳转的页面,增加点击事件,跳转到你创建的web-view页面,并传递URL参数:例如:/pages/index/index
javascript
<template>
<view>
<uni-list>
<uni-list-item
title="打开外部链接"
@click="openExternalUrl('https://super.xiaoxilao.com/')"
></uni-list-item>
</uni-list>
</view>
</template>
<script>
export default {
methods: {
openExternalUrl(url) {
uni.navigateTo({
url: `/pages/web-view/web-view?url=${encodeURIComponent(url)}`
});
}
}
}
</script>
<style>
/* 你的样式 */
</style>