vue method support async/await or not ?

Created on 2 Dec 2017  路  3Comments  路  Source: vuejs/vue

.babelrc : es2017
Vue: 2.2.6

`
methods: {
async getTaskList(){
let data = await this.$store.dispatch('TaskList', tid)
console.log("TaskList", data);
}
},

mounted() {
this.getTaskList();
}
`
But I got the error in chrome console:

vue.esm.js?65d7:479 [Vue warn]: Error in mounted hook: "ReferenceError: regeneratorRuntime is not defined"

Most helpful comment

I find the solution:
1.

npm install --save-dev babel-plugin-transform-runtime

  1. modify .babelrc

{ "presets": [ "es2017", ["env", "commonjs"], "stage-2" ], "plugins": [["transform-runtime", { "polyfill": false, "regenerator": true }]] }

All 3 comments

Hello, your issue has been closed because it does not conform to our issue requirements. Please use the Issue Helper to create an issue - thank you!

I find the solution:
1.

npm install --save-dev babel-plugin-transform-runtime

  1. modify .babelrc

{ "presets": [ "es2017", ["env", "commonjs"], "stage-2" ], "plugins": [["transform-runtime", { "polyfill": false, "regenerator": true }]] }

You should just include regenerator-runtime or babel-polyfill by yourself rather than use babel-plugin-transform-runtime which will increase your bundle size.

Was this page helpful?
0 / 5 - 0 ratings