python通信,联调接口

This commit is contained in:
2025-04-07 18:26:39 +08:00
parent 489112d028
commit 758fdb49c2
8 changed files with 143 additions and 87 deletions

View File

@@ -12,18 +12,25 @@ export function usePythonBridge() {
};
// 调用 Python 方法
const callPython = (data) => {
if (bridge.value) {
bridge.value.stringFromJs(data);
}
const fetchDataConfig = (data) => {
return new Promise((resolve, reject) => {
if (!bridge.value) {
reject(new Error('返回出错,请检查是否已连接到 Python'));
return;
}
bridge.value.fetchDataConfig(data, function (result) {
resolve(result);
});
});
};
// 从 Python 获取数据
const getPythonData = () => {
const getPythonData = (data) => {
if (bridge.value) {
bridge.value.stringToJs(function (result) {
alert(result);
});
bridge.value.stringToJs(data, function (result) {
alert(result);
});
}
};
@@ -31,7 +38,7 @@ export function usePythonBridge() {
onMounted(initBridge);
return {
callPython,
fetchDataConfig,
getPythonData
};
}