
Product
Introducing Socket Firewall Enterprise: Flexible, Configurable Protection for Modern Package Ecosystems
Socket Firewall Enterprise is now available with flexible deployment, configurable policies, and expanded language support.
vue-async-computed
Advanced tools
Async computed properties for Vue
With this plugin, you can have have computed properties in Vue that are computed asynchronously.
Without using this plugin, you can't do this:
new Vue({
data: {
userId: 1
},
computed: {
username: {
// Using vue-resource
return Vue.http.get('/get-username-by-id', { id: this.userId })
}
}
}
Or rather, you could, but it wouldn't do what you'd want it to do. But using this plugin, it works just like you'd expect:
new Vue({
data: {
userId: 1
},
asyncComputed: {
username: {
return Vue.http.get('/get-username-by-id', { id: this.userId })
}
}
}
This is especily useful with ES7 async functions:
````js
new Vue({
asyncComputed: {
async someCalculation () {
const x = await someAsycFunction()
const y = await anotherAsyncFunction()
return x + y
}
}
})
## Install
```sh
npm install --save vue-async-computed
```
## Usage example
```js
import AsyncComputed from 'vue-async-computed'
/* Initialize the plugin */
Vue.use(AsyncComputed)
/* Then, when you create a Vue instance (or component),
you can pass an object named "asyncComputed" as well as
or instead of one named "computed". The functions you pass
to "asyncComputed" should return promises, and the values
those promises resolve to are then asynchronously bound to
the Vue instance as the promises resolve. Just like with
normal computed properties, if the data the property depends
on changes then the property is re-run automatically.
You can almost completely ignore the fact that behind the
scenes they are asynchronous. The one thing to remember is
that until a asynchronously property's promise resolves
for the first time, the value of the computed property is null.
*/
const vm = new Vue({
data: {
x: 2,
y: 3
},
asyncComputed: {
sum () {
const sum = this.x + this.y
return new Promise(resolve =>
setTimeout(() => resolve(sum), 1000)
)
}
}
})
/* Until one second has passed, vm.sum will be null.
After that, vm.sum will be 5. If you change vm.x or vm.y,
one second later vm.sum will automaticly update itself to be
the sum of what you set vm.x and vm.y to be a second before.
*/
MIT © Benjamin Fox
FAQs
Async computed properties for Vue
The npm package vue-async-computed receives a total of 15,010 weekly downloads. As such, vue-async-computed popularity was classified as popular.
We found that vue-async-computed demonstrated a not healthy version release cadence and project activity because the last version was released a year ago. It has 2 open source maintainers collaborating on the project.
Did you know?

Socket for GitHub automatically highlights issues in each pull request and monitors the health of all your open source dependencies. Discover the contents of your packages and block harmful activity before you install or update your dependencies.

Product
Socket Firewall Enterprise is now available with flexible deployment, configurable policies, and expanded language support.

Security News
Open source dashboard CNAPulse tracks CVE Numbering Authorities’ publishing activity, highlighting trends and transparency across the CVE ecosystem.

Product
Detect malware, unsafe data flows, and license issues in GitHub Actions with Socket’s new workflow scanning support.