Skip to content
This repository was archived by the owner on Dec 26, 2018. It is now read-only.

Commit bb2e57b

Browse files
committed
umd
1 parent da614d2 commit bb2e57b

File tree

4 files changed

+30
-6
lines changed

4 files changed

+30
-6
lines changed

README.md

Lines changed: 10 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -11,18 +11,24 @@ npm install vue-async-data
1111
### Usage
1212

1313
``` js
14+
// assuming CommonJS
1415
var Vue = require('vue')
15-
var asyncData = require('vue-async-data')
16+
var VueAsyncData = require('vue-async-data')
1617

1718
// use globally
1819
// you can also just use `asyncData.mixin` where needed
19-
Vue.use(asyncData)
20+
Vue.use(VueAsyncData)
2021
```
2122

2223
Then, in your component options, provide an `asyncData` function:
2324

2425
``` js
2526
Vue.component('example', {
27+
data: function {
28+
return {
29+
msg: 'not loaded yet...'
30+
}
31+
},
2632
asyncData: function (resolve, reject) {
2733
// load data and call resolve(data)
2834
// 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:
4046

4147
``` js
4248
Vue.component('example', {
49+
// ...
4350
asyncData: function () {
4451
return someServiceThatReturnsPromise.get(12345)
4552
.then(function (msg) {
@@ -55,6 +62,7 @@ Parallel fetching with `Promise.all` and ES6:
5562

5663
``` js
5764
Vue.component('example', {
65+
// ...
5866
asyncData() {
5967
return Promise.all([
6068
serviceA.get(123),

example/example.build.js

Lines changed: 10 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -10138,7 +10138,7 @@
1013810138

1013910139
/***/ },
1014010140
/* 68 */
10141-
/***/ function(module, exports) {
10141+
/***/ function(module, exports, __webpack_require__) {
1014210142

1014310143
var asyncData = {
1014410144
created: function () {
@@ -10174,13 +10174,21 @@
1017410174
}
1017510175
}
1017610176

10177-
module.exports = {
10177+
var api = {
1017810178
mixin: asyncData,
1017910179
install: function (Vue, options) {
1018010180
Vue.options = Vue.util.mergeOptions(Vue.options, asyncData)
1018110181
}
1018210182
}
1018310183

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+
1018410192

1018510193
/***/ }
1018610194
/******/ ]);

package.json

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -2,7 +2,7 @@
22
"name": "vue-async-data",
33
"version": "1.0.0",
44
"description": "async data loading plugin for Vue.js",
5-
"main": "index.js",
5+
"main": "vue-async-data.js",
66
"repository": {
77
"type": "git",
88
"url": "git+https://github.com/vuejs/vue-async-data.git"

index.js renamed to vue-async-data.js

Lines changed: 9 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -32,9 +32,17 @@ var asyncData = {
3232
}
3333
}
3434

35-
module.exports = {
35+
var api = {
3636
mixin: asyncData,
3737
install: function (Vue, options) {
3838
Vue.options = Vue.util.mergeOptions(Vue.options, asyncData)
3939
}
4040
}
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+
}

0 commit comments

Comments
 (0)