update examples for asyncData

This commit is contained in:
Alexandre Chopin 2017-02-28 15:17:49 +01:00
parent 7f925c22fa
commit a4461ff590
18 changed files with 18 additions and 18 deletions

View File

@ -9,7 +9,7 @@
<script>
export default {
data ({ req }, callback) {
asyncData ({ req }, callback) {
setTimeout(function () {
// callback(err, data)
callback(null, {

View File

@ -11,7 +11,7 @@
import axios from 'axios'
export default {
async data ({ params }) {
async asyncData ({ params }) {
// We can use async/await ES6 feature
let { data } = await axios.get(`https://jsonplaceholder.typicode.com/posts/${params.id}`)
return { post: data }

View File

@ -15,7 +15,7 @@
import axios from 'axios'
export default {
data ({ req, params }) {
asyncData ({ req, params }) {
// We can return a Promise instead of calling the callback
return axios.get('https://jsonplaceholder.typicode.com/posts')
.then((res) => {

View File

@ -8,7 +8,7 @@
<script>
export default {
layout: 'dark',
data ({ req }) {
asyncData ({ req }) {
return {
name: req ? 'server' : 'client'
}

View File

@ -7,7 +7,7 @@
<script>
export default {
data () {
asyncData () {
return new Promise((resolve) => {
setTimeout(function () {
resolve({})

View File

@ -7,7 +7,7 @@
<script>
export default {
data () {
asyncData () {
return new Promise((resolve) => {
setTimeout(function () {
resolve({ name: 'world' })

View File

@ -13,7 +13,7 @@
import axios from 'axios'
export default {
data () {
asyncData () {
return axios.get('https://jsonplaceholder.typicode.com/users')
.then((res) => {
return { users: res.data }

View File

@ -14,7 +14,7 @@ export default {
validate ({ params }) {
return !isNaN(+params.id)
},
data ({ params, error }) {
asyncData ({ params, error }) {
return axios.get(`https://jsonplaceholder.typicode.com/users/${+params.id}`)
.then((res) => res.data)
.catch(() => {

View File

@ -1,6 +1,6 @@
<script>
export default {
data ({ req }) {
asyncData ({ req }) {
return {
name: req ? 'server' : 'client'
}

View File

@ -7,7 +7,7 @@
<script>
export default {
data ({ req }) {
asyncData ({ req }) {
return {
name: req ? 'server' : 'client'
}

View File

@ -11,7 +11,7 @@
<script>
export default {
data ({ store, route, userAgent }) {
asyncData ({ store, route, userAgent }) {
return {
userAgent,
slugs: [

View File

@ -16,7 +16,7 @@
<script>
export default {
data ({ env }) {
asyncData ({ env }) {
return { users: env.users }
}
}

View File

@ -10,7 +10,7 @@ export default {
validate ({ params }) {
return !isNaN(+params.id)
},
data ({ params, env, error }) {
asyncData ({ params, env, error }) {
const user = env.users.find((user) => String(user.id) === params.id)
if (!user) {
return error({ message: 'User not found', statusCode: 404 })

View File

@ -9,7 +9,7 @@
import axios from 'axios'
export default {
data () {
asyncData () {
return axios.get('https://jsonplaceholder.typicode.com/photos/4').then(res => res.data)
}
}

View File

@ -23,7 +23,7 @@ export default {
if (!from) return 'slide-left'
return +to.query.page < +from.query.page ? 'slide-right' : 'slide-left'
},
data ({ query }) {
asyncData ({ query }) {
const page = +query.page || 1
return axios.get('https://reqres.in/api/users?page=' + page)
.then((res) => {

View File

@ -9,7 +9,7 @@
<script>
export default {
data ({ req }) {
asyncData ({ req }) {
return {
name: req ? 'server' : 'client'
}

View File

@ -7,7 +7,7 @@
<script>
export default {
data ({ req, isServer }) {
asyncData ({ req, isServer }) {
return {
name: req ? 'server' : 'client'
}

View File

@ -17,7 +17,7 @@
import socket from '~plugins/socket.io.js'
export default {
data (context, callback) {
asyncData (context, callback) {
socket.emit('last-messages', function (messages) {
callback(null, {
messages,