Why is it that some of the vue source code is added through the Vue.prototype.fun method, and some are directly added by Vue.fun?

clipboard.png

clipboard.png
I am confused when I read the vue source code for the first time today.

Mar.04,2021

thanks for medicine

function  Obj(){

}
Obj.a=1
Obj.d=4
Obj.prototype.a=2
var c=new Obj()
console.log(c.a)//2
console.log(c.d)//undefined

subcomponents (classes) can inherit methods of parent components (classes) through prototype, while directly defined methods cannot be used in subcomponents


you can think of Vue as a class (that is, class Vue {} in ES6 or function Vue () {} in ES5).

In the

figure, Vue.use is the class method of Vue , that is, the method called directly through Vue.use () . This method is used to extend the plug-ins of Vue . If you want to use some plug-ins in the project, such as Element UI , you need to introduce them through this method.

and the method defined by Vue.pototype.fun is a method used within a Vue component, that is, if you want to use the method fun , you need to call it within the component defined with Vue , not directly using Vue.fun .


the difference between static methods and instance methods. Vue.prototype.fun is the add instance method, and Vue.fun is the add static method.


is the difference between class methods and instance methods

Menu