Skip to content

Instantly share code, notes, and snippets.

@tarnagas
Created May 20, 2019 13:46
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save tarnagas/725a99e20647a1c6fdc272d93f3325d5 to your computer and use it in GitHub Desktop.
Save tarnagas/725a99e20647a1c6fdc272d93f3325d5 to your computer and use it in GitHub Desktop.
'use strict'
/**
* Sample of use
*
* ```js
* import { path as MediasPath } from './vue/medias/forms'
* import { content_type as WorksContentType } from './vue/works/forms'
* appify({
* components: {
* 'medias-path': MediasPath,
* 'works-content_type': WorksContentType
* }
* })
* ```
*/
import Vue from 'vue'
/**
* @param {Object} options
*/
export default function (options = {}) {
options.id = options.id || 'app'
options.components = options.components || {}
appify(options.id, options.components)
}
/**
* @param {String} id
* @param {Object} components
*/
const appify = function (id, components = {}) {
/**
* @param {String} id
* @param {Object} components
* @returns {Vue | CombinedVueInstance<Vue, object, object, object, Record<never, any>>}
* @private
*/
let _vue = function (id, components) {
Object.entries(components).forEach((i) => Vue.component(i[0], i[1]))
let vue = (id) => new Vue({ el: `#${id}` })
return vue(id)
}
window.addEventListener('DOMContentLoaded', () => _vue(id, components))
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment