You signed in with another tab or window. Reload to refresh your session.You signed out in another tab or window. Reload to refresh your session.You switched accounts on another tab or window. Reload to refresh your session.Dismiss alert
// D:\OutPut\VUE\vue\src\core\global-api\assets.jsexportfunctioninitAssetRegisters(Vue: GlobalAPI){/** * Create asset registration methods. */ASSET_TYPES.forEach(type=>{Vue[type]=function(id: string,definition: Function|Object): Function|Object|void{if(!definition){returnthis.options[type+'s'][id]}else{/* istanbul ignore if */if(process.env.NODE_ENV!=='production'&&type==='component'){validateComponentName(id)}if(type==='component'&&isPlainObject(definition)){definition.name=definition.name||iddefinition=this.options._base.extend(definition)}if(type==='directive'&&typeofdefinition==='function'){
definition ={bind: definition,update: definition}}this.options[type+'s'][id]=definitionreturndefinition}}})}
vue.extend
//D:\OutPut\VUE\vue\src\core\global-api\extend.js
/* @flow */import{ASSET_TYPES}from'shared/constants'import{defineComputed,proxy}from'../instance/state'import{extend,mergeOptions,validateComponentName}from'../util/index'exportfunctioninitExtend(Vue: GlobalAPI){/** * Each instance constructor, including Vue, has a unique * cid. This enables us to create wrapped "child * constructors" for prototypal inheritance and cache them. */Vue.cid=0letcid=1/** * Class inheritance */Vue.extend=function(extendOptions: Object): Function{extendOptions=extendOptions||{}constSuper=thisconstSuperId=Super.cidconstcachedCtors=extendOptions._Ctor||(extendOptions._Ctor={})if(cachedCtors[SuperId]){returncachedCtors[SuperId]}constname=extendOptions.name||Super.options.nameif(process.env.NODE_ENV!=='production'&&name){validateComponentName(name)}constSub=functionVueComponent(options){this._init(options)}Sub.prototype=Object.create(Super.prototype)Sub.prototype.constructor=SubSub.cid=cid++Sub.options=mergeOptions(Super.options,extendOptions)Sub['super']=Super// For props and computed properties, we define the proxy getters on// the Vue instances at extension time, on the extended prototype. This// avoids Object.defineProperty calls for each instance created.if(Sub.options.props){initProps(Sub)}if(Sub.options.computed){initComputed(Sub)}// allow further extension/mixin/plugin usageSub.extend=Super.extendSub.mixin=Super.mixinSub.use=Super.use// create asset registers, so extended classes// can have their private assets too.ASSET_TYPES.forEach(function(type){Sub[type]=Super[type]})// enable recursive self-lookupif(name){Sub.options.components[name]=Sub}// keep a reference to the super options at extension time.// later at instantiation we can check if Super's options have// been updated.Sub.superOptions=Super.optionsSub.extendOptions=extendOptionsSub.sealedOptions=extend({},Sub.options)// cache constructorcachedCtors[SuperId]=SubreturnSub}}functioninitProps(Comp){constprops=Comp.options.propsfor(constkeyinprops){proxy(Comp.prototype,`_props`,key)}}functioninitComputed(Comp){constcomputed=Comp.options.computedfor(constkeyincomputed){defineComputed(Comp.prototype,key,computed[key])}}
自己的简化实现
The text was updated successfully, but these errors were encountered:
vue的实现
组件注册方法在这里
vue.extend
//D:\OutPut\VUE\vue\src\core\global-api\extend.js
自己的简化实现
The text was updated successfully, but these errors were encountered: