Skip to content

Commit

Permalink
examples(with-sockets): deprecated callback and use cjs (#7650)
Browse files Browse the repository at this point in the history
  • Loading branch information
ReadB committed Jul 2, 2020
1 parent d8dace9 commit 86f69e4
Show file tree
Hide file tree
Showing 3 changed files with 16 additions and 20 deletions.
2 changes: 1 addition & 1 deletion examples/with-sockets/nuxt.config.js
@@ -1,4 +1,4 @@
export default {
module.exports = {
head: {
meta: [
{ charset: 'utf-8' },
Expand Down
22 changes: 11 additions & 11 deletions examples/with-sockets/pages/index.vue
Expand Up @@ -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>
Expand All @@ -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'
Expand Down
12 changes: 4 additions & 8 deletions examples/with-sockets/server.js
@@ -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
Expand Down

0 comments on commit 86f69e4

Please sign in to comment.