Skip to content

Opener 打开插件

Opener 插件用于打开外部 URL、文件或目录。

打开 URL

typescript
import { openUrl } from '@tauri-apps/plugin-opener'

// 在默认浏览器中打开
await openUrl('https://tauri.ruoyi.plus/')

打开文件

typescript
import { openPath } from '@tauri-apps/plugin-opener'

// 用系统默认程序打开文件
await openPath('/path/to/document.pdf')

打开目录

typescript
import { revealItemInDir } from '@tauri-apps/plugin-opener'

// 在文件管理器中显示
await revealItemInDir('/path/to/folder')

实际使用场景

tsx
import { openUrl } from '@tauri-apps/plugin-opener'
import { Button } from 'antd'
import { ExternalLink } from 'lucide-react'

function AboutPage() {
  return (
    <div>
      <Button
        icon={<ExternalLink size={14} />}
        onClick={() => openUrl('https://tauri.ruoyi.plus/')}
      >
        访问官网
      </Button>
    </div>
  )
}

基于 Tauri 2.x 构建的企业级桌面应用开发框架