W3Cschool
恭喜您成為首批注冊(cè)用戶
獲得88經(jīng)驗(yàn)值獎(jiǎng)勵(lì)
命令處理程序可以接受參數(shù):
#[tauri::command]
fn my_custom_command(invoke_message: String) {
println!("I was invoked from JS, with this message: {}", invoke_message);
}
參數(shù)應(yīng)該作為帶有駝峰式鍵的 JSON 對(duì)象傳遞:
invoke('my_custom_command', { invokeMessage: 'Hello!' })
參數(shù)可以是任何類型,只要它們實(shí)現(xiàn)了 serde::Deserialize
。
請(qǐng)注意,在 Rust 中使用 snake_case 聲明參數(shù)時(shí),參數(shù)會(huì)轉(zhuǎn)換為 JavaScript 的 camelCase。
要在 JavaScript 中使用snake_case,您必須在語(yǔ)句中聲明它:tauri::command
#[tauri::command(rename_all = "snake_case")]
fn my_custom_command(invoke_message: String) {
println!("I was invoked from JS, with this message: {}", invoke_message);
}
對(duì)應(yīng)的 JavaScript:
invoke('my_custom_command', { invoke_message: 'Hello!' })
Copyright©2021 w3cschool編程獅|閩ICP備15016281號(hào)-3|閩公網(wǎng)安備35020302033924號(hào)
違法和不良信息舉報(bào)電話:173-0602-2364|舉報(bào)郵箱:jubao@eeedong.com
掃描二維碼
下載編程獅App
編程獅公眾號(hào)
聯(lián)系方式:
更多建議: