Let Vue methods support promise
npm install --save vue-methods-promise
// Installation
import Vue from 'vue'
import vueMethodsPromise from 'vue-methods-promise'
Vue.use(vueMethodsPromise, {
hookName: '$promise', // Component default hook name
promise: (mp) => { // Promise callback
mp
.then((function (res) {
console.log(res)
})
.catch(function (err) {
console.log(err.msg) // Test error
})
}
})
// Usage
export default {
mounted () {
this.test()
},
methods: { // All return Promise type, will be dealt with
test () {
return Promise.reject(new Error({ msg: 'Test error' }))
}
}
}