Tauri 获取file dialog full path

src-tauri/Cargo.toml
[dependencies]
tauri = { version = "1.5", features = ["shell-open", "dialog-all"] }

src-tauri/tauri.conf.json
{
  "build": {
    "withGlobalTauri": true
  },
  "tauri": {
    "allowlist": {
      "dialog": {
        "all": true, // enable all dialog APIs
        "ask": true, // enable dialog ask API
        "confirm": true, // enable dialog confirm API
        "message": true, // enable dialog message API
        "open": true, // enable file open API
        "save": true // enable file save API
      }
    }
  }
}

ui/index.html
<script type="module">
const dialog = window.__TAURI__.dialog;
// Open a selection dialog for image files
const selected = await dialog.open({
multiple: true,
filters: [{
name: 'Image',
extensions: ['png', 'jpeg']
}]
});
if (Array.isArray(selected)) {
// user selected multiple files
} else if (selected === null) {
// user cancelled the selection
} else {
// user selected a single file
}
</script>

发表回复

您的电子邮箱地址不会被公开。 必填项已用*标注

12 + 20 =