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
{{ message }}
This repository has been archived by the owner on Feb 9, 2021. It is now read-only.
vue-router
在
vue-rotuer
源码中,vuejs
的插件开发是依赖通过插件install
方法 动态 传入的Vue
对象。这是为了避免单独import Vue
将导致插件直接依赖Vuejs
,进而导致package
包含Vuejs
,即插件体积增大。通过在插件的
install
模块中建立一个缓存容器来缓存作为参数被传入的Vue
对象。此时,Vue
是作为参数 动态 传入,并不是作为函数中的静态变量而存在。那么仅在调用install
方法时,Vue
对象才会被传入。那么也就避免了在插件install
函数中直接依赖Vue
对象。同时也并不影响插件在被调用时对Vue
对象的依赖。总结
纵观
vuejs
的插件开发原理,无论是在以后自己开发vuejs
插件还是其他库,都可利用 将依赖转变为参数 的方式来避免package
体积增大。即避免了模块对其他模块的直接依赖。这个思路个人认为比较适合插件开发,因为它的依赖动态引入原理极大地限制了插件的dependcies
。Reference
Vue-rotuer/index.js
Vue-router/install.js
Vuejs 技术揭秘
The text was updated successfully, but these errors were encountered: