|
|
@@ -74,6 +74,8 @@ export default {
|
|
|
},
|
|
|
created() {
|
|
|
this.videoRecommendWrapper(this.nextId)
|
|
|
+ this.getHotVideoWrapper()
|
|
|
+ // this.initServerSendEvent()
|
|
|
},
|
|
|
mounted() {
|
|
|
// 当窗口宽度改变时获取屏幕宽度
|
|
|
@@ -83,12 +85,6 @@ export default {
|
|
|
this.screenWidth = window.screenWidth
|
|
|
}
|
|
|
}
|
|
|
-
|
|
|
- getHotVideo().then(resp => {
|
|
|
- if (resp.code === 0) {
|
|
|
- this.carouselList = resp.data
|
|
|
- }
|
|
|
- })
|
|
|
},
|
|
|
methods: {
|
|
|
videoRecommendWrapper(nextId) {
|
|
|
@@ -133,6 +129,30 @@ export default {
|
|
|
setTimeout(() => {
|
|
|
this.videoRecommendWrapper(this.nextId)
|
|
|
}, 1000)
|
|
|
+ },
|
|
|
+ getHotVideoWrapper() {
|
|
|
+ getHotVideo().then(resp => {
|
|
|
+ if (resp.code === 0) {
|
|
|
+ this.carouselList = resp.data
|
|
|
+ }
|
|
|
+ })
|
|
|
+ },
|
|
|
+ initServerSendEvent() {
|
|
|
+ var list = this.carouselList
|
|
|
+ if (typeof (EventSource) !== 'undefined') {
|
|
|
+ const sseUrl = 'https://api.reghao.cn/api/data/video/hot'
|
|
|
+ const source = new EventSource(sseUrl)
|
|
|
+ source.addEventListener('test', function(e) {
|
|
|
+ console.log(e)
|
|
|
+ })
|
|
|
+ source.onmessage = function(event) {
|
|
|
+ console.log(event)
|
|
|
+ console.log(list)
|
|
|
+ // list.push(event.data)
|
|
|
+ }
|
|
|
+ } else {
|
|
|
+ console.log('抱歉,你的浏览器不支持 SSE...')
|
|
|
+ }
|
|
|
}
|
|
|
}
|
|
|
}
|