InitializeThe.vue 1.8 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566
  1. <template>
  2. <view>
  3. <!-- <web-view :webview-styles="" :src=""></web-view> -->
  4. </view>
  5. </template>
  6. <script>
  7. export default {
  8. data() {
  9. return {
  10. userList:{
  11. /* id:'',
  12. nickname:'',
  13. password:'',
  14. remak1:'',
  15. username:'',
  16. remak2:'', */
  17. },
  18. userid:'',
  19. list:[],
  20. }
  21. },
  22. onLoad() {
  23. this.getUserList();
  24. },
  25. methods: {
  26. async getUserList() {
  27. let _this = this;
  28. // 创建一个this.socketTask对象【发送、接收、关闭socket都由这个对象操作】
  29. this.socketTask_getUserList = uni.connectSocket({
  30. // 【非常重要】必须确保你的服务器是成功的,如果是手机测试千万别使用ws://127.0.0.1:9099【特别容易犯的错误】
  31. url: 'ws://117.78.18.24:9988/websocket/pageNumber_4/functionNumber_3/all',
  32. success(data) {
  33. console.log(data);
  34. }
  35. });
  36. /* let windpowerstationid = uni.getStorageSync('windpowerstationName'); */
  37. // 消息的发送和接收必须在正常连接打开中,才能发送或接收【否则会失败】
  38. this.socketTask_getUserList.onOpen(res => {
  39. console.log('WebSocket连接正常打开中...!');
  40. this.is_open_socket = true;
  41. // 注:只有连接正常打开中 ,才能正常收到消息
  42. this.socketTask_getUserList.onMessage(res => {/*
  43. console.log("收到服务器内容:" + res.data); */
  44. /* _this.windpowerstationdetail.getUserList = JSON.parse(res.data); */
  45. _this.userList = JSON.parse(res.data);
  46. _this.userid = uni.getStorageSync('userid');
  47. let list = [{}];
  48. for(let i =0;i<_this.userList.length;i++){
  49. list[i] = {};
  50. list[i].id =_this.userList[i].id+'-'+_this.userid;
  51. }
  52. _this.list = list;
  53. console.log(list);
  54. });
  55. });
  56. },
  57. }
  58. }
  59. </script>
  60. <style>
  61. </style>