Skip to content

Latest commit

 

History

History
47 lines (42 loc) · 1.49 KB

README.md

File metadata and controls

47 lines (42 loc) · 1.49 KB

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