From dfdab1aa564b1e9339a34a14fd7f882c68debc23 Mon Sep 17 00:00:00 2001 From: whychdw <49690745@qq.com> Date: 星期一, 16 九月 2019 10:58:01 +0800 Subject: [PATCH] 添加数据连接 --- src/index.js | 55 +++++++++++++++++++++++++++++++++++++++++++++++++++++++ 1 files changed, 55 insertions(+), 0 deletions(-) diff --git a/src/index.js b/src/index.js index 4a486a6..a010eac 100644 --- a/src/index.js +++ b/src/index.js @@ -30,4 +30,59 @@ Android.onJsFunctionCalled(2000); }, 2000); } + + var vm = new Vue({ + el: '#appStates', + data: { + timer: new Timeout(), + web: { + info: true, + error: false, + } + }, + methods: { + setWeb: function(bool) { + if(bool) { + this.web.info = true; + this.web.error = false; + }else { + this.web.info = false; + this.web.error = true; + } + }, + startCheck: function() { + var self = this; + this.timer.start(function() { + self.checkServerStates(); + }, 2000); + }, + checkServerStates: function() { + var self = this; + var searchParams = { + num: 2 + }; + var json = JSON.stringify(searchParams); + // 璇锋眰鍚庡彴 + ajax({ + url: 'Batt_rtstateAction!serchByInfo', + data: 'json='+json, + success: function(res) { + //console.log(res); + self.setWeb(true); + }, + error: function() { + // 璁剧疆鏈嶅姟鍣ㄨ繛鎺ョ姸鎬佸紓甯� + self.setWeb(); + }, + complete: function() { + // 寮�鍚鏃跺櫒 + self.timer.open(); + }, + }); + } + }, + mounted() { + this.startCheck(); + }, + }); }); \ No newline at end of file -- Gitblit v1.9.1