查询列表功能
This commit is contained in:
37
src/utils/pythonBridge.js
Normal file
37
src/utils/pythonBridge.js
Normal file
@@ -0,0 +1,37 @@
|
||||
// pythonBridge.js
|
||||
import { ref, onMounted } from 'vue';
|
||||
|
||||
export function usePythonBridge() {
|
||||
const bridge = ref(null);
|
||||
|
||||
// 初始化 QWebChannel
|
||||
const initBridge = () => {
|
||||
new QWebChannel(qt.webChannelTransport, (channel) => {
|
||||
bridge.value = channel.objects.bridge;
|
||||
});
|
||||
};
|
||||
|
||||
// 调用 Python 方法
|
||||
const callPython = (data) => {
|
||||
if (bridge.value) {
|
||||
bridge.value.stringFromJs(data);
|
||||
}
|
||||
};
|
||||
|
||||
// 从 Python 获取数据
|
||||
const getPythonData = () => {
|
||||
if (bridge.value) {
|
||||
bridge.value.stringToJs(function (result) {
|
||||
alert(result);
|
||||
});
|
||||
}
|
||||
};
|
||||
|
||||
// 在组件挂载时初始化桥接
|
||||
onMounted(initBridge);
|
||||
|
||||
return {
|
||||
callPython,
|
||||
getPythonData
|
||||
};
|
||||
}
|
||||
Reference in New Issue
Block a user