Skip to content

Commit

Permalink
perf: Register global mixins from plugins
Browse files Browse the repository at this point in the history
Follow Vue doc's recommendations for preventing duplicate global mixins application:
https://vuejs.org/v2/guide/mixins.html#Global-Mixin
  • Loading branch information
paulgv committed Jul 20, 2019
1 parent 2d1d729 commit 2ceb8e4
Show file tree
Hide file tree
Showing 2 changed files with 20 additions and 9 deletions.
17 changes: 11 additions & 6 deletions src/plugins/routing.js
Original file line number Diff line number Diff line change
Expand Up @@ -116,15 +116,20 @@ function getRouteBaseNameFactory (contextRoute) {
}
}

Vue.mixin({
methods: {
localePath: localePathFactory('$i18n', '$router'),
switchLocalePath: switchLocalePathFactory('$i18n'),
getRouteBaseName: getRouteBaseNameFactory()
const plugin = {
install(Vue) {
Vue.mixin({
methods: {
localePath: localePathFactory('$i18n', '$router'),
switchLocalePath: switchLocalePathFactory('$i18n'),
getRouteBaseName: getRouteBaseNameFactory()
}
})
}
})
}

export default ({ app, route }) => {
Vue.use(plugin)
app.localePath = localePathFactory('i18n', 'router')
app.switchLocalePath = switchLocalePathFactory('i18n')
app.getRouteBaseName = getRouteBaseNameFactory(route)
Expand Down
12 changes: 9 additions & 3 deletions src/plugins/seo.js
Original file line number Diff line number Diff line change
@@ -1,6 +1,12 @@
import Vue from 'vue'
import { nuxtI18nSeo } from './seo-head'

Vue.mixin({
head: nuxtI18nSeo
})
const plugin = {
install(Vue) {
Vue.mixin({
head: nuxtI18nSeo
})
}
}

Vue.use(plugin)

0 comments on commit 2ceb8e4

Please sign in to comment.