我是tauri的新手,我面临着从@tauri应用程序/api获取数据的问题。
"@tauri-apps/api": "^1.1.0",
"@tauri-apps/cli": "^1.1.1"以下是我的反应代码:
/index.jsx
import {getTauriVersion} from "@tauri-apps/api/app"
function App() {
const func = async () => {
const res = await getTauriVersion()
return res
}
return (<></>)
}这是我的tauri.conf.json
{
"build": {
"beforeDevCommand": "npm run dev",
"beforeBuildCommand": "npm run build",
"devPath": "http://localhost:1420",
"distDir": "../dist",
"withGlobalTauri": true
},
...
"tauri": {
"allowList": {"all": true}
}
}错误是:
Uncaught (in promise) TypeError: window.__TAURI_IPC__ is not a function
unhandledRejection: ReferenceError: window is not defined
at o (file:///C:/test/test/node_modules/@tauri-apps/api/tauri-
a4b3335a.js:1:100)发布于 2022-09-22 17:46:07
造成这种错误的典型的两个来源是:
发布于 2022-11-30 10:02:58
你可以写一个函数来判断
const handleIsTauri = () => {
return Boolean(
typeof window !== 'undefined' &&
window !== undefined &&
window.__TAURI_IPC__ !== undefined
)};https://stackoverflow.com/questions/73817185
复制相似问题