SocketServer.vue 1.7 KB

1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950515253545556575859606162636465666768697071727374757677
  1. <template>
  2. <div id="app-base-httpserver">
  3. <div class="one-block-1">
  4. <span>
  5. 1. 内置socket-io server服务
  6. </span>
  7. </div>
  8. <div class="one-block-2">
  9. <a-space>
  10. <p>* 状态:{{ currentStatus }}</p>
  11. </a-space>
  12. <p>* 地址:{{ servicAddress }}</p>
  13. </div>
  14. <div class="one-block-1">
  15. <span>
  16. 2. 发送请求
  17. </span>
  18. </div>
  19. <div class="one-block-2">
  20. <a-space>
  21. <a-button @click="sendRequest('downloads')"> 打开【我的下载】 </a-button>
  22. </a-space>
  23. </div>
  24. </div>
  25. </template>
  26. <script>
  27. import { io } from 'socket.io-client'
  28. import { ipcApiRoute, requestHttp } from '@/api/main'
  29. export default {
  30. data() {
  31. return {
  32. currentStatus: '关闭',
  33. servicAddress: 'ws://127.0.0.1:7070'
  34. };
  35. },
  36. mounted () {
  37. this.init();
  38. },
  39. methods: {
  40. init () {
  41. const self = this;
  42. this.socket = io(this.servicAddress);
  43. this.socket.on('connect', () => {
  44. console.log('connect!!!!!!!!');
  45. self.currentStatus = '开启';
  46. });
  47. },
  48. sendRequest (id) {
  49. if (this.currentStatus == '关闭') {
  50. this.$message.error('socketio服务未开启');
  51. return;
  52. }
  53. const method = ipcApiRoute.doSocketRequest;
  54. this.socket.emit('c1', { cmd: method, params: {id: id} }, (response) => {
  55. // response为返回值
  56. console.log('response:', response)
  57. });
  58. },
  59. }
  60. };
  61. </script>
  62. <style lang="less" scoped>
  63. #app-base-httpserver {
  64. padding: 0px 10px;
  65. text-align: left;
  66. width: 100%;
  67. .one-block-1 {
  68. font-size: 16px;
  69. padding-top: 10px;
  70. }
  71. .one-block-2 {
  72. padding-top: 10px;
  73. }
  74. }
  75. </style>