zoukankan      html  css  js  c++  java
  • new Vue 会发生什么

    new Vue的时候会调用Vue源码里的core/instance/init,js文件

    export function initMixin (Vue: Class<Component>) {
      Vue.prototype._init = function (options?: Object) {
        const vm: Component = this
        // a uid
        vm._uid = uid++
    
        let startTag, endTag
        /* istanbul ignore if */
        if (process.env.NODE_ENV !== 'production' && config.performance && mark) {
          startTag = `vue-perf-start:${vm._uid}`
          endTag = `vue-perf-end:${vm._uid}`
          mark(startTag)
        }
    
        // a flag to avoid this being observed
        vm._isVue = true
        // merge options
        if (options && options._isComponent) {  //1.首先是对options合并
          // optimize internal component instantiation
          // since dynamic options merging is pretty slow, and none of the
          // internal component options needs special treatment.
          initInternalComponent(vm, options)
        } else {
          vm.$options = mergeOptions(
            resolveConstructorOptions(vm.constructor),
            options || {},
            vm
          )
        }
        /* istanbul ignore else */
        if (process.env.NODE_ENV !== 'production') {
          initProxy(vm)
        } else {
          vm._renderProxy = vm
        }
        // expose real self 2.执行一系列init方法
        vm._self = vm
        initLifecycle(vm)
        initEvents(vm)
        initRender(vm)
        callHook(vm, 'beforeCreate')
        initInjections(vm) // resolve injections before data/props
        initState(vm)
        initProvide(vm) // resolve provide after data/props
        callHook(vm, 'created')
    
        /* istanbul ignore if */
        if (process.env.NODE_ENV !== 'production' && config.performance && mark) {
          vm._name = formatComponentName(vm, false)
          mark(endTag)
          measure(`vue ${vm._name} init`, startTag, endTag)
        }
    
        if (vm.$options.el) { //3.最后调用$mount去挂载
          vm.$mount(vm.$options.el)
        }
      }
    }
  • 相关阅读:
    浏览器渲染
    微信h5页面制作总结
    chrome开发工具指南之综述
    零碎记录
    docker 容器已经启动,但是无法访问
    Docker的安装及使用
    python目录选择
    centos7 设置进程开机自启动
    语句中传入变量
    kafka -> structuredStreaming读取kafka日志 ->自定义输出到mysql
  • 原文地址:https://www.cnblogs.com/TTblog5/p/12856000.html
Copyright © 2011-2022 走看看