kamijin-fanta/vue-async-data

asyncData and computed not support,has error!

Closed this issue · 1 comments

like this:

export default {
  name: 'show-data',
  asyncData: {
    list() {
      return new Promise((resolve, reject) => {
        setTimeout(_ => {
          resolve([
	  	{id:0,name:"衣服",type:0},
       		{id:1,name:"券",type:1}
	])
        }, 1000);
      })
    },
  },
computed: {
type0Data(){
			    return this.list.filter(function (m) {
			      	return m.type===0
			    })
			},
}
}

@AaronChen2012 List is undefined until promise is resolved. It may be solved by specifying a default value. please see the README.

export default {
  name: 'show-data',
  asyncData: {
    listDefault: [],
    list() {
      return new Promise((resolve, reject) => {
        setTimeout(_ => {
          resolve([
	  	{id:0,name:"衣服",type:0},
       		{id:1,name:"券",type:1}
	])
        }, 1000);
      })
    },
  },
}