python通信,联调接口
This commit is contained in:
@@ -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
|
||||
};
|
||||
}
|
||||
Reference in New Issue
Block a user