diff --git a/assets/js/main.ts b/assets/js/main.ts index 96751fc..b13ce2d 100644 --- a/assets/js/main.ts +++ b/assets/js/main.ts @@ -1,5 +1,7 @@ import { createApp } from './lib/petite-vue.es.js' +const apiUrl = 'http://localhost:8125/api/system/poll/service/pclt-0001' + const appdata = { $delimiters: ['{|', '|}'], urlParams: new URL(location.href).searchParams, @@ -20,30 +22,21 @@ function save() { this.newdata = '' } -const apiUrl = 'http://localhost:8125/api/system/poll/service/pclt-0001' - -async function dopoll(obj: typeof appdata) { +async function dopoll(obj: typeof appdata, url: string) { while (true) { - let res = await fetch('http://localhost:8125/api/system/poll/service/pclt-0001') - //let res = await fetch(apiUrl) - let data = await res.json() - console.log(data) - obj.newdata = data['status'] + try { + let res = await fetch(url) + let data = await res.json() + console.log(data) + obj.newdata = data['status'] + } catch (error) { + console.log(error) + await new Promise(r => setTimeout(r, 10000)) + } } } function poll() { - dopoll(this) -} - -function x_poll() { - fetch('http://localhost:8125/api/system/poll/service/pclt-0001') - .then((res) => res.json()) - .then((data) => { - console.log(data) - this.newdata = data['status'] - this.poll() - }) - return null + dopoll(this, apiUrl) }