文章目录
- 一、前言
- 二、实现方法
- 1.前端部分
- 2.后端部分
- 3.依赖文件
- 三、运行结果
一、前言
以往开发桌面应用通常都是页面接口一起写,这样开发周期比较长,且页面样式不灵活,如果能把页面交给前端写的话,就可前后端并行开发桌面应用了,并且css语言灵活好用样式丰富。下面介绍一种 Python + vue 的桌面应用开发模式(之前我有讲过另一种也是 python + vue 的桌面应用开发,耦合度更低,但不支持双向通信,详情可参考 这篇文章)
二、实现方法
1.前端部分
test_webchannel.html
<!DOCTYPE html>
<html lang="en"><head><meta charset="UTF-8"><script src="./static/js/qwebchannel.js" type="text/javascript"></script><script src="./static/js/qwebchannel_mapping.js" type="text/javascript"></script><script src="./static/js/vue.js" type="text/javascript"></script>
</head><body><div id="app"><span @click="search_book(search_key)" style="cursor: pointer;">点击检索 "{{ search_key }}" 相关图书</span><hr><div>{{result}}</div></div><script>// 创建一个新的 Vue 实例或者说是 Vue 应用new