Created
November 6, 2018 10:31
-
-
Save cairin/447ed3d01625b33e29c2633fbb560eb5 to your computer and use it in GitHub Desktop.
Simple vue plugin ecample
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
// in /src/plugins/ directory | |
import Vue from 'vue' | |
const Example = { | |
install (Vue, options) { | |
Vue.prototype.$methodName = (param) => { | |
// Your code here. | |
} | |
Vue.prototype.$methodName1 = (param1, param2) => { | |
// Your code here. | |
} | |
} | |
} | |
Vue.use(Example) |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
// The Vue build version to load with the `import` command | |
// (runtime-only or standalone) has been set in webpack.base.conf with an alias. | |
import Vue from 'vue' | |
import App from './App' | |
import router from './router' | |
import store from './store' | |
import './plugins/example.js' // This imports the chat plugin and makes it available in components via this.$methodName | |
// Other stuff here | |
/* eslint-disable no-new */ | |
new Vue({ | |
el: '#app', | |
router, | |
store, | |
components: { App }, | |
template: '<App/>' | |
}) |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment