mirror of
https://github.com/nuxt/nuxt.git
synced 2025-02-17 06:01:34 +00:00
examples(with-sockets): deprecated callback and use cjs (#7650)
This commit is contained in:
parent
d8dace9748
commit
86f69e4429
@ -1,4 +1,4 @@
|
||||
export default {
|
||||
module.exports = {
|
||||
head: {
|
||||
meta: [
|
||||
{ charset: 'utf-8' },
|
||||
|
@ -4,10 +4,10 @@
|
||||
<li class="chat page">
|
||||
<div class="chatArea">
|
||||
<ul ref="messages" class="messages">
|
||||
<li v-for="(message, index) in messages" :key="index" class="message">
|
||||
<i :title="message.date">
|
||||
{{ message.date.split('T')[1].slice(0, -2) }}
|
||||
</i>: {{ message.text }}
|
||||
<li v-for="(msg, index) in messages" :key="index" class="message">
|
||||
<i :title="msg.date">
|
||||
{{ msg.date.split('T')[1].slice(0, -2) }}
|
||||
</i>: {{ msg.text }}
|
||||
</li>
|
||||
</ul>
|
||||
</div>
|
||||
@ -21,13 +21,13 @@
|
||||
import socket from '~/plugins/socket.io.js'
|
||||
|
||||
export default {
|
||||
asyncData (context, callback) {
|
||||
socket.emit('last-messages', function (messages) {
|
||||
callback(null, {
|
||||
messages,
|
||||
message: ''
|
||||
})
|
||||
})
|
||||
asyncData () {
|
||||
return new Promise(resolve =>
|
||||
socket.emit('last-messages', messages => resolve({ messages }))
|
||||
)
|
||||
},
|
||||
data () {
|
||||
return { message: '' }
|
||||
},
|
||||
watch: {
|
||||
messages: 'scrollToBottom'
|
||||
|
@ -1,16 +1,12 @@
|
||||
import http from 'http'
|
||||
|
||||
import { Nuxt, Builder } from 'nuxt'
|
||||
import express from 'express'
|
||||
import SocketIO from 'socket.io'
|
||||
|
||||
const port = process.env.PORT || 3000
|
||||
const isProd = process.env.NODE_ENV === 'production'
|
||||
|
||||
const app = express()
|
||||
const http = require('http')
|
||||
const app = require('express')()
|
||||
const server = http.createServer(app)
|
||||
const io = SocketIO(server)
|
||||
const io = require('socket.io')(server)
|
||||
|
||||
const { Nuxt, Builder } = require('nuxt')
|
||||
// We instantiate Nuxt.js with the options
|
||||
const config = require('./nuxt.config.js')
|
||||
config.dev = !isProd
|
||||
|
Loading…
Reference in New Issue
Block a user