Skip to content

Instantly share code, notes, and snippets.

@Yumshot
Created November 7, 2023 02:29
Show Gist options
  • Save Yumshot/29f9b815f9b5a5e67d91043d22d13d8a to your computer and use it in GitHub Desktop.
Save Yumshot/29f9b815f9b5a5e67d91043d22d13d8a to your computer and use it in GitHub Desktop.
main.rs
// Prevents additional console window on Windows in release, DO NOT REMOVE!!
#![cfg_attr(not(debug_assertions), windows_subsystem = "windows")]
// Learn more about Tauri commands at https://tauri.app/v1/guides/features/command
#[tauri::command]
fn greet(name: &str) -> String {
format!("Hello, {}! You've been greeted from Rust!", name)
}
#[tauri::command]
fn greet2() -> [u8; 5] {
[1, 2, 3, 4, 5]
}
fn main() {
tauri::Builder::default()
.invoke_handler(tauri::generate_handler![greet, greet2])
.run(tauri::generate_context!())
.expect("error while running tauri application");
}
greet.vue
<script setup lang="ts">
import { ref } from "vue";
import { invoke } from "@tauri-apps/api/tauri";
const greetMsg = ref("");
const name = ref("");
async function greet() {
// Learn more about Tauri commands at https://tauri.app/v1/guides/features/command
greetMsg.value = await invoke("greet", { name: name.value });
}
async function greet2() {
// Learn more about Tauri commands at https://tauri.app/v1/guides/features/command
greetMsg.value = await invoke("greet2");
}
</script>
<template>
<form class="row" @submit.prevent="greet2">
<input id="greet-input" v-model="name" placeholder="Enter a name..." />
<button type="submit">Greet</button>
</form>
<p>{{ greetMsg }}</p>
</template>
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment