// main.rs#![cfg_attr(not(debug_assertions), windows_subsystem = "windows")]#[tauri::command]fngreet(name:&str)->String{format!("Hello, {}! You've been greeted from Rust!", name)}#[tauri::command]fnhello(what:&str)->String{format!("what do you want,{}",what)}fnmain(){tauri::Builder::default().invoke_handler(tauri::generate_handler![greet, hello])// .invoke_handler(tauri::generate_handler![hello]).run(tauri::generate_context!()).expect("error while running tauri application");}
// Greet.vue
<scriptsetuplang="ts">import{ ref }from"vue";import{ invoke }from"@tauri-apps/api/tauri";const greetMsg =ref("");const name =ref("");const helloMsg =ref("");const what=ref("");asyncfunctiongreet(){
greetMsg.value =awaitinvoke("greet",{ name: name.value });}asyncfunctionhello(){
helloMsg.value =awaitinvoke("hello",{ what: what.value});}</script><template><divclass="greet"><inputid="greet-input"v-model="name"placeholder="Enter a name..."/><buttontype="button"@click="greet()">Greet</button></div><divclass="hello"><!-- v-model 显示what内容 --><inputid="hello-input"v-model="what"placeholder="what do you want"/><buttontype="button"@click="hello()">What</button></div><p>{{ greetMsg }}</p><p>{{ helloMsg }}</p></template>
// App.vue
<scriptsetuplang="ts">// This starter template is using Vue 3 <script setup> SFCs// Check out https://vuejs.org/api/sfc-script-setup.html#script-setupimport Greet from"./components/Greet.vue";</script><template><divclass="container"><Greet/></div></template>