Vue 2.0 使用的 options API,本质是一个类在例时传入一个 options 对象,这个 options 对象有很多的属性。
let vm = new Vue({el: '#app',data() {return {a: 1,}},computed: {// ...},methods: {// ...},// ...});
Vue 构造函数 / 类
由此可知,Vue 就是一个构造函数(ES5)或是一个类(ES6)
然后为 Vue.prototype 添加上方法与函数
- 定义 init 方法,用于 Vue 的所有初始化
- 把实例 this 定义为 vm 变量, 以防止混乱
 - 将 options 挂载到实例 vm 上
 - 调用初始化的方法
- initState 
- eg. data / computed 等等
 
 - initMinx
 - …
 
 - initState 
 
 
vue/index.js
import { initState, initMixin } from './init';function Vue (options) {this._init(options);}// 定义 init 方法,用于 Vue 的所有初始化Vue.prototype._init = function (options) {var vm = this; // 把实例 this 定义为 vm 变量, 以防止混乱vm.$options = options; // 将 options 挂载到实例 vm 上initState(vm); // 调用初始化状态的方法initMixin(vm); // 其实的初始化方法 ...}export default Vue;
定义所有初始化
用于存入所有初始化的方法
init.js
function initState (vm) {}function initMixin (vm) {}// ... 其它的需要初始化的方法export {initState,initMixin,// ...}
