外观
openLink 打开链接
约 167 字小于 1 分钟
2024-01-01
介绍
提供跨平台打开外部链接的功能。
openLink(url: string): Promise
- 参数
- url: 要打开的链接地址
- 返回值
<Promise>无
示例代码
<template>
<view>
<text>打开链接示例</text>
<button @click="openExternalLink">打开外部链接</button>
<button @click="openLocalPage" type="primary">打开本地页面</button>
</view>
</template>
<script setup lang="uts">
import { openLink } from '@/uni_modules/uview-unix'
// 打开外部链接
const openExternalLink = async () => {
try {
await openLink('https://www.example.com')
console.log('链接打开成功')
} catch (error) {
console.error('链接打开失败:', error)
}
}
// 打开本地页面
const openLocalPage = async () => {
try {
await openLink('/pages/detail/index?id=123')
console.log('本地页面打开成功')
} catch (error) {
console.error('本地页面打开失败:', error)
}
}
</script>