vue-methodly
Version:
A simple Vue plugin to augment your Vue instance methods with custom ones
91 lines (72 loc) • 1.18 kB
Markdown
A simple Vue plugin to augment your Vue instance methods with custom ones
```bash
npm install vue-methodly --save
```
or
```bash
yarn add vue-methodly --save
```
```html
<script src="https://unpkg.com/vue-methodly"></script>
```
```js
import VueMethodly from 'vue-methodly'
...
Vue.use(VueMethodly, {
methods: [
{
// the name of your custom method
name: 'myCustomMethod',
// the native hook on which to execute
hook: 'mounted'
},
...
]
})
...
```
```js
// some component
...
export default {
...
// gets executed before the native mounted() hook
myCustomMethod () {
// whatever you like here
},
...
}
...
```
```js
Vue.use(VueMethodly, {
methods: [
{
// the name of your custom method
name: 'myCustomMethod',
// the hook before which to execute
hook: 'mounted'
},
...
]
})
```
```js
Vue.component('MyComponent', {
...
// gets executed before the native mounted() hook
myCustomMethod () {
// whatever you like here
},
...
})
```
https://jsfiddle.net/yprbeh5f/