Skip to content

Instantly share code, notes, and snippets.

@cairin
Created November 6, 2018 10:31
Show Gist options
  • Save cairin/447ed3d01625b33e29c2633fbb560eb5 to your computer and use it in GitHub Desktop.
Save cairin/447ed3d01625b33e29c2633fbb560eb5 to your computer and use it in GitHub Desktop.
Simple vue plugin ecample
// 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)
// 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