Ohm-Management - Projektarbeit B-ME
You can not select more than 25 topics Topics must start with a letter or number, can include dashes ('-') and can be up to 35 characters long.

install.js 1.4KB

12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849505152
  1. import View from './components/view'
  2. import Link from './components/link'
  3. export let _Vue
  4. export function install (Vue) {
  5. if (install.installed && _Vue === Vue) return
  6. install.installed = true
  7. _Vue = Vue
  8. const isDef = v => v !== undefined
  9. const registerInstance = (vm, callVal) => {
  10. let i = vm.$options._parentVnode
  11. if (isDef(i) && isDef(i = i.data) && isDef(i = i.registerRouteInstance)) {
  12. i(vm, callVal)
  13. }
  14. }
  15. Vue.mixin({
  16. beforeCreate () {
  17. if (isDef(this.$options.router)) {
  18. this._routerRoot = this
  19. this._router = this.$options.router
  20. this._router.init(this)
  21. Vue.util.defineReactive(this, '_route', this._router.history.current)
  22. } else {
  23. this._routerRoot = (this.$parent && this.$parent._routerRoot) || this
  24. }
  25. registerInstance(this, this)
  26. },
  27. destroyed () {
  28. registerInstance(this)
  29. }
  30. })
  31. Object.defineProperty(Vue.prototype, '$router', {
  32. get () { return this._routerRoot._router }
  33. })
  34. Object.defineProperty(Vue.prototype, '$route', {
  35. get () { return this._routerRoot._route }
  36. })
  37. Vue.component('RouterView', View)
  38. Vue.component('RouterLink', Link)
  39. const strats = Vue.config.optionMergeStrategies
  40. // use the same hook merging strategy for route hooks
  41. strats.beforeRouteEnter = strats.beforeRouteLeave = strats.beforeRouteUpdate = strats.created
  42. }