Skip to content

Commit 670a1d5

Browse files
When used in a script tag automatically install on global Vue instance
1 parent d08dd4a commit 670a1d5

File tree

4 files changed

+43
-5
lines changed

4 files changed

+43
-5
lines changed

CHANGELOG.md

+7-3
Original file line numberDiff line numberDiff line change
@@ -2,6 +2,7 @@
22
<!-- DON'T EDIT THIS SECTION, INSTEAD RE-RUN doctoc TO UPDATE -->
33
# Changelog
44

5+
- [v2.1.1](#v211)
56
- [v2.1.0](#v210)
67
- [v2.0.0](#v200)
78
- [v1.4.0](#v140)
@@ -11,15 +12,18 @@
1112

1213
<!-- END doctoc generated TOC please keep comment here to allow auto update -->
1314

15+
### v2.1.1
16+
* Automatic installation when used in a script tag.
17+
1418
### v2.1.0
1519
* Allow object syntax for defining computed properties.
16-
* Enable custom default values
20+
* Enable custom default values.
1721

1822
### v2.0.0
19-
* Now compatible with Vue 2.0
23+
* Now compatible with Vue 2.0.
2024

2125
### v1.4.0
22-
* Add CommonJS support
26+
* Add CommonJS support.
2327

2428
### v1.2.0
2529
* Use the same strategy to merge `asyncComputed` objects as regular `computed` objects.

LICENSE

+1-1
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,6 @@
11
This software is released under the MIT license:
22

3-
Copyright (c) 2016 Benjamin Fox [email protected]
3+
Copyright (c) 2016 Benjamin Fox <[email protected]>
44

55
Permission is hereby granted, free of charge, to any person obtaining a copy of
66
this software and associated documentation files (the "Software"), to deal in

README.md

+22
Original file line numberDiff line numberDiff line change
@@ -94,6 +94,28 @@ new Vue({
9494
npm install --save vue-async-computed
9595
````
9696
97+
Alternately, you can link it directly from a CDN:
98+
99+
````html
100+
<script src="https://unpkg.com/vue-async-computed"></script>
101+
<!--
102+
That will always point to the latest version of vue-async-computed.
103+
You probably want to instead pin it to a specific version:
104+
-->
105+
<script src="https://unpkg.com/[email protected]"></script>
106+
````
107+
108+
When used with a module system such as `webpack` or `browserify`, you need to explicitly install `vue-async-computed` via `Vue.use()`:
109+
110+
````js
111+
import Vue from 'vue'
112+
import AsyncComputed from 'vue-async-computed'
113+
114+
Vue.use(AsyncComputed)
115+
````
116+
117+
You don't need to do this when using global script tags. So long as you include `vue-async-computed` in a script tag after Vue itself, it will be installed automatically.
118+
97119
## Usage example
98120

99121
````js

src/index.js

+13-1
Original file line numberDiff line numberDiff line change
@@ -1,9 +1,14 @@
11
const prefix = '_async_computed$'
22

3-
export default {
3+
let installed = false
4+
5+
const AsyncComputed = {
46
install (Vue, options) {
57
options = options || {}
68

9+
if (installed) return
10+
installed = true
11+
712
Vue.config
813
.optionMergeStrategies
914
.asyncComputed = Vue.config.optionMergeStrategies.computed
@@ -59,3 +64,10 @@ export default {
5964
})
6065
}
6166
}
67+
68+
export default AsyncComputed
69+
70+
// Auto install in dist mode
71+
if (typeof window !== 'undefined' && window.Vue) {
72+
window.Vue.use(AsyncComputed)
73+
}

0 commit comments

Comments
 (0)