This repository was archived by the owner on Dec 26, 2018. It is now read-only.
File tree Expand file tree Collapse file tree 4 files changed +30
-6
lines changed Expand file tree Collapse file tree 4 files changed +30
-6
lines changed Original file line number Diff line number Diff line change @@ -11,18 +11,24 @@ npm install vue-async-data
11
11
### Usage
12
12
13
13
``` js
14
+ // assuming CommonJS
14
15
var Vue = require (' vue' )
15
- var asyncData = require (' vue-async-data' )
16
+ var VueAsyncData = require (' vue-async-data' )
16
17
17
18
// use globally
18
19
// you can also just use `asyncData.mixin` where needed
19
- Vue .use (asyncData )
20
+ Vue .use (VueAsyncData )
20
21
```
21
22
22
23
Then, in your component options, provide an ` asyncData ` function:
23
24
24
25
``` js
25
26
Vue .component (' example' , {
27
+ data : function {
28
+ return {
29
+ msg : 'not loaded yet...'
30
+ }
31
+ },
26
32
asyncData : function (resolve , reject ) {
27
33
// load data and call resolve(data)
28
34
// or call reject(reason) if something goes wrong
@@ -40,6 +46,7 @@ You can also return a promise that resolves to the data to be set:
40
46
41
47
``` js
42
48
Vue .component (' example' , {
49
+ // ...
43
50
asyncData : function () {
44
51
return someServiceThatReturnsPromise .get (12345 )
45
52
.then (function (msg ) {
@@ -55,6 +62,7 @@ Parallel fetching with `Promise.all` and ES6:
55
62
56
63
``` js
57
64
Vue .component (' example' , {
65
+ // ...
58
66
asyncData () {
59
67
return Promise .all ([
60
68
serviceA .get (123 ),
Original file line number Diff line number Diff line change 10138
10138
10139
10139
/***/ } ,
10140
10140
/* 68 */
10141
- /***/ function ( module , exports ) {
10141
+ /***/ function ( module , exports , __webpack_require__ ) {
10142
10142
10143
10143
var asyncData = {
10144
10144
created : function ( ) {
@@ -10174,13 +10174,21 @@
10174
10174
}
10175
10175
}
10176
10176
10177
- module . exports = {
10177
+ var api = {
10178
10178
mixin : asyncData ,
10179
10179
install : function ( Vue , options ) {
10180
10180
Vue . options = Vue . util . mergeOptions ( Vue . options , asyncData )
10181
10181
}
10182
10182
}
10183
10183
10184
+ if ( true ) {
10185
+ module . exports = api
10186
+ } else if ( typeof define === 'function' && define . amd ) {
10187
+ define ( function ( ) { return api } )
10188
+ } else if ( typeof window !== 'undefined' ) {
10189
+ window . VueAsyncData = api
10190
+ }
10191
+
10184
10192
10185
10193
/***/ }
10186
10194
/******/ ] ) ;
Original file line number Diff line number Diff line change 2
2
"name" : " vue-async-data" ,
3
3
"version" : " 1.0.0" ,
4
4
"description" : " async data loading plugin for Vue.js" ,
5
- "main" : " index .js" ,
5
+ "main" : " vue-async-data .js" ,
6
6
"repository" : {
7
7
"type" : " git" ,
8
8
"url" : " git+https://github.com/vuejs/vue-async-data.git"
Original file line number Diff line number Diff line change @@ -32,9 +32,17 @@ var asyncData = {
32
32
}
33
33
}
34
34
35
- module . exports = {
35
+ var api = {
36
36
mixin : asyncData ,
37
37
install : function ( Vue , options ) {
38
38
Vue . options = Vue . util . mergeOptions ( Vue . options , asyncData )
39
39
}
40
40
}
41
+
42
+ if ( typeof exports === 'object' && typeof module === 'object' ) {
43
+ module . exports = api
44
+ } else if ( typeof define === 'function' && define . amd ) {
45
+ define ( function ( ) { return api } )
46
+ } else if ( typeof window !== 'undefined' ) {
47
+ window . VueAsyncData = api
48
+ }
You can’t perform that action at this time.
0 commit comments