|
@@ -142,17 +142,19 @@ export default {
|
|
|
})
|
|
})
|
|
|
},
|
|
},
|
|
|
initServerSendEvent() {
|
|
initServerSendEvent() {
|
|
|
- var list = this.carouselList
|
|
|
|
|
if (typeof (EventSource) !== 'undefined') {
|
|
if (typeof (EventSource) !== 'undefined') {
|
|
|
const sseUrl = 'https://api.reghao.cn/api/data/video/hot'
|
|
const sseUrl = 'https://api.reghao.cn/api/data/video/hot'
|
|
|
const source = new EventSource(sseUrl)
|
|
const source = new EventSource(sseUrl)
|
|
|
source.addEventListener('test', function(e) {
|
|
source.addEventListener('test', function(e) {
|
|
|
console.log(e)
|
|
console.log(e)
|
|
|
})
|
|
})
|
|
|
|
|
+
|
|
|
|
|
+ const that = this
|
|
|
source.onmessage = function(event) {
|
|
source.onmessage = function(event) {
|
|
|
- console.log(event)
|
|
|
|
|
- console.log(list)
|
|
|
|
|
- // list.push(event.data)
|
|
|
|
|
|
|
+ const dataList = JSON.parse(event.data)
|
|
|
|
|
+ if (dataList.length !== 0) {
|
|
|
|
|
+ that.carouselList = dataList
|
|
|
|
|
+ }
|
|
|
}
|
|
}
|
|
|
} else {
|
|
} else {
|
|
|
console.log('抱歉,你的浏览器不支持 SSE...')
|
|
console.log('抱歉,你的浏览器不支持 SSE...')
|