/vue-methods-promise

Let Vue methods support return Promise

Primary LanguageJavaScript

Build Status dependencies Status devDependencies Status Known Vulnerabilities npm npm

vue-methods-promise

Let Vue methods support promise

Usage

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' }))
    }
  }
}