< 返回版块

廴壬吉 发表于 2023-10-26 15:03

评论区

写评论
作者 廴壬吉 2023-10-27 13:48

谢谢,让前端传给后端

wtto00 2023-10-27 12:08

好像读不了,可以用事件试试。 后端:

$[tauri::command]
fn get_local_storage<R: tauri::Runtime>(app:tauri::AppHandle<R>){
  app.emit_all("tauri://get-local-storage");
}

然后前端:

async function sendLocalStorage(){
  const tauriApi = await import('@tauri-apps/api');
  const {event:{listen,emit}} = tauriApi;
  listen('tauri://get-local-storage',() => {
     emit('local-storage',{key:'key',value:localStorage.getItem(key)})
  })
}

然后后端:

fn main() {
  tauri::Builder::default()
    .setup(|app| {
      app.listen_global("local-storage", |event| {
        println!("got event-name with payload {:?}", event.payload());
      });
      Ok(())
    })
    .run(tauri::generate_context!())
    .expect("failed to run app");
}

大概是这个流程吧

gorust21 2023-10-27 09:04

localStorage?

1 共 3 条评论, 1 页