UNPKG

1.64 kBPlain TextView Raw
1import OurVue, { VueConstructor } from 'vue'
2import { VuetifyUseOptions } from 'types'
3import { consoleError } from './util/console'
4
5export function install (Vue: VueConstructor, args: VuetifyUseOptions = {}) {
6 if ((install as any).installed) return
7 (install as any).installed = true
8
9 if (OurVue !== Vue) {
10 consoleError('Multiple instances of Vue detected\nSee https://github.com/vuetifyjs/vuetify/issues/4068\n\nIf you\'re seeing "$attrs is readonly", it\'s caused by this')
11 }
12
13 const components = args.components || {}
14 const directives = args.directives || {}
15
16 for (const name in directives) {
17 const directive = directives[name]
18
19 Vue.directive(name, directive)
20 }
21
22 (function registerComponents (components: any) {
23 if (components) {
24 for (const key in components) {
25 const component = components[key]
26 if (component && !registerComponents(component.$_vuetify_subcomponents)) {
27 Vue.component(key, component as typeof Vue)
28 }
29 }
30 return true
31 }
32 return false
33 })(components)
34
35 // Used to avoid multiple mixins being setup
36 // when in dev mode and hot module reload
37 // https://github.com/vuejs/vue/issues/5089#issuecomment-284260111
38 if (Vue.$_vuetify_installed) return
39 Vue.$_vuetify_installed = true
40
41 Vue.mixin({
42 beforeCreate () {
43 const options = this.$options as any
44
45 if (options.vuetify) {
46 options.vuetify.init(this, options.ssrContext)
47 this.$vuetify = Vue.observable(options.vuetify.framework)
48 } else {
49 this.$vuetify = (options.parent && options.parent.$vuetify) || this
50 }
51 },
52 })
53}