Ipc.vue 1.4 KB

1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950515253545556575859
  1. <template>
  2. <div>
  3. <div>
  4. <h3 :style="{ marginBottom: '16px' }">
  5. demo3-1 渲染进程与主进程IPC通信
  6. </h3>
  7. <a-list bordered>
  8. <!-- <a-button @click="helloHandle">打招呼</a-button> -->
  9. <a-input-search v-model="content" @search="helloHandle">
  10. <a-button slot="enterButton">
  11. send
  12. </a-button>
  13. </a-input-search>
  14. </a-list>
  15. </div>
  16. <div style="margin-top: 20px;">
  17. <h3 :style="{ marginBottom: '16px' }">
  18. demo3-2 主进程API执行网页函数
  19. </h3>
  20. <a-list bordered>
  21. <a-input-search v-model="content2" @search="executeJSHandle">
  22. <a-button slot="enterButton">
  23. send
  24. </a-button>
  25. </a-input-search>
  26. </a-list>
  27. </div>
  28. </div>
  29. </template>
  30. <script>
  31. import { localApi } from '@/api/main'
  32. export default {
  33. data() {
  34. return {
  35. content: 'hello',
  36. content2: 'hello world',
  37. reply: ''
  38. }
  39. },
  40. methods: {
  41. helloHandle(value) {
  42. const self = this;
  43. this.$callMain('example.hello', value).then(r => {
  44. self.$message.info(r);
  45. })
  46. },
  47. executeJSHandle(value) {
  48. localApi('executeJS', {str: value}).then(res => {
  49. if (res.code == 0) {
  50. console.log(res.data);
  51. }
  52. }).catch(err => {
  53. console.log('err:', err)
  54. })
  55. }
  56. }
  57. }
  58. </script>
  59. <style></style>