[feature-request] async/await methods in Vue 2.0
See original GitHub issueHey, starting with koa on back-end, a lot of stuff are moving to async/await (*/yield for now), what I suggest is adding async/await functions support to methods so it’s allowed to do like:
import DBService from './db'
new Vue({
el: document.body,
data: {
user: {},
friends: []
},
methods: {
async getUserData () {
this.user = await DBService.getUser()
this.friends = await DBService.getFriends(this.user.id)
}
}
})
This looks like a cleaner way of doing async stuff to me, what do you think?
P.S. Same can be used for Vuex actions.
Issue Analytics
- State:
- Created 7 years ago
- Reactions:12
- Comments:10 (5 by maintainers)
Top Results From Across the Web
How to use Async/Await with Vue.js Components
We can simply declare the created () method as async and perform our asynchronous actions inside. In this example, we are loading a...
Read more >How to Use Async and Await with Vue.js Apps - Medium
Vue.js is a great framework for building front end web apps. ... In the save function of the methods object, we have: async...
Read more >Async / Await method in Vue.js - Stack Overflow
Try to wait for method too: async getTreeView(){ await fetch("myurl /*just a URL */", { method: 'GET', }) .then((response) ...
Read more >Data Fetching - Nuxt
In Nuxt we have 2 ways of getting data from an API. We can use the fetch method or the asyncData method. Nuxt...
Read more >Asynchronous Behavior | Vue Test Utils
You may have noticed some other parts of the guide using await when calling some methods on wrapper , such as trigger and...
Read more >Top Related Medium Post
No results found
Top Related StackOverflow Question
No results found
Troubleshoot Live Code
Lightrun enables developers to add logs, metrics and snapshots to live code - no restarts or redeploys required.
Start FreeTop Related Reddit Thread
No results found
Top Related Hackernoon Post
No results found
Top Related Tweet
No results found
Top Related Dev.to Post
No results found
Top Related Hashnode Post
No results found
Top GitHub Comments
And you can’t? I didn’t test it, but I think you can.
Just remember that
methods
is an object, so it should be:Same for actions. It’s mentioned here https://github.com/vuejs/vuex/releases/tag/v2.0.0-rc.1
@NicolasParada, btw, my notation is shortand just like: