123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566 |
- <template>
- <view>
- <!-- <web-view :webview-styles="" :src=""></web-view> -->
- </view>
- </template>
- <script>
- export default {
- data() {
- return {
- userList:{
- /* id:'',
- nickname:'',
- password:'',
- remak1:'',
- username:'',
- remak2:'', */
- },
- userid:'',
- list:[],
- }
- },
- onLoad() {
- this.getUserList();
- },
- methods: {
- async getUserList() {
- let _this = this;
- // 创建一个this.socketTask对象【发送、接收、关闭socket都由这个对象操作】
- this.socketTask_getUserList = uni.connectSocket({
- // 【非常重要】必须确保你的服务器是成功的,如果是手机测试千万别使用ws://127.0.0.1:9099【特别容易犯的错误】
- url: 'ws://117.78.18.24:9988/websocket/pageNumber_4/functionNumber_3/all',
- success(data) {
- console.log(data);
- }
- });
- /* let windpowerstationid = uni.getStorageSync('windpowerstationName'); */
- // 消息的发送和接收必须在正常连接打开中,才能发送或接收【否则会失败】
- this.socketTask_getUserList.onOpen(res => {
- console.log('WebSocket连接正常打开中...!');
- this.is_open_socket = true;
-
- // 注:只有连接正常打开中 ,才能正常收到消息
- this.socketTask_getUserList.onMessage(res => {/*
- console.log("收到服务器内容:" + res.data); */
- /* _this.windpowerstationdetail.getUserList = JSON.parse(res.data); */
- _this.userList = JSON.parse(res.data);
- _this.userid = uni.getStorageSync('userid');
- let list = [{}];
- for(let i =0;i<_this.userList.length;i++){
- list[i] = {};
- list[i].id =_this.userList[i].id+'-'+_this.userid;
- }
- _this.list = list;
- console.log(list);
- });
- });
- },
-
- }
- }
- </script>
- <style>
- </style>
|