Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

examples(with-sockets): deprecated callback and use cjs #7650

Merged
merged 3 commits into from Jul 2, 2020
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Jump to
Jump to file
Failed to load files.
Diff view
Diff view
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