<template>
  <view class="w-body">
    <w-public />
    <w-navbar left-back fixed title="SSE使用示例"></w-navbar>
		<view class="w-pre">{{ text }}</view>
  </view>
</template>

<script setup>
import { onLoad, onShow, onReady, onUnload, onHide } from "@dcloudio/uni-app";
import { ref, getCurrentInstance } from "vue";
import { SSE } from "@/SSE";


const { proxy } = getCurrentInstance();

const text = ref("")

let sse = undefined;
onLoad(()=>{
	console.debug("onLoad")
})

onShow(()=>{
	console.debug("onShow")
});

onReady(()=>{
	console.debug("onReady")
})

onUnload(()=>{
	console.debug("onUnload")
})

onShow(()=>{
	sse = SSE.post("/sse-test", {}, (data) => {
    console.debug(data);
		text.value += '\n'+JSON.stringify(data)
  })
});

onUnload(() => {
  sse.close();
});
</script>

<style lang="scss" scoped>
.w-body {
  --navbar-height: 44px;
  background-color: var(--w-bg);
  font-size: 0.9rem;
  min-height: 100vh;
}
</style>
