vue构造函数,里这几个是怎么样的存在?
这几个是啥类型?用户可以自定义一个类似的东西吗?

回答
就字面而言依次代表路由,存储,国际化三个变量。
通常 router 使用 vue-router 实例,store 是 vuex 实例。
事实上三者通常用在单页面应用,多语言,本质上都是对Vue类型的扩展。
Vue.mixin({    beforeCreate () {
      // 如果路由不存在 this.$options.router 在 new Vue({router})的时候引入
      if (isDef(this.$options.router)) {
        this._routerRoot = this
        this._router = this.$options.router
        this._router.init(this)
        Vue.util.defineReactive(this, '_route', this._router.history.current)
      } else {
        this._routerRoot = (this.$parent && this.$parent._routerRoot) || this
      }
      // 注册路由实列
      registerInstance(this, this)
    },
    destroyed () {
      registerInstance(this)
    }
  })
我们先通过Vue.use(VueRouter)注入beforeCreate生命周期函数,然后new Vue()的调用的时候,从而获取router的实例进行注册
以上是 vue构造函数,里这几个是怎么样的存在? 的全部内容, 来源链接: utcz.com/a/41627.html








