(vm, propsOptions)
| 4892 | |
| 4893 | //初始化props 检验props 数据格式是否是规范的如果是规范的则添加到观察者队列中 |
| 4894 | function initProps(vm, propsOptions) { |
| 4895 | var propsData = vm.$options.propsData || {}; |
| 4896 | var props = vm._props = {}; |
| 4897 | // cache prop keys so that future props updates can iterate using Array |
| 4898 | //缓存道具键,以便以后道具更新可以使用数组迭代 |
| 4899 | // instead of dynamic object key enumeration. |
| 4900 | //而不是动态对象键枚举。 |
| 4901 | var keys = vm.$options._propKeys = []; |
| 4902 | var isRoot = !vm.$parent; |
| 4903 | // root instance props should be converted |
| 4904 | //应该转换根实例道具 |
| 4905 | if (!isRoot) { //则不会监听 观察者 |
| 4906 | toggleObserving(false); |
| 4907 | } |
| 4908 | var loop = function (key) { |
| 4909 | keys.push(key); |
| 4910 | /* |
| 4911 | 验证支柱 验证 prosp 是否是规范数据 并且为props 添加 value.__ob__ 属性,把prosp添加到观察者中 |
| 4912 | * 校验 props 参数 就是组建 定义的props 类型数据,校验类型 |
| 4913 | * |
| 4914 | * 判断prop.type的类型是不是Boolean或者String,如果不是他们两类型,调用getPropDefaultValue获取默认值并且把value添加到观察者模式中 |
| 4915 | */ |
| 4916 | var value = validateProp( |
| 4917 | key, //props 对象的key |
| 4918 | propsOptions, |
| 4919 | propsData, |
| 4920 | vm |
| 4921 | ); |
| 4922 | /* istanbul ignore else 伊斯坦布尔忽略其他 */ |
| 4923 | { |
| 4924 | //大写字母,加完减号又转成小写了 比如把驼峰 aBc 变成了 a-bc |
| 4925 | //匹配大写字母并且两面不是空白的 替换成 - 在转换成小写 |
| 4926 | var hyphenatedKey = hyphenate(key); |
| 4927 | // 检查属性是否为保留属性。 |
| 4928 | //var isReservedAttribute = makeMap('key,ref,slot,slot-scope,is'); |
| 4929 | if (isReservedAttribute(hyphenatedKey) || |
| 4930 | config.isReservedAttr(hyphenatedKey)) { |
| 4931 | //输出警告 |
| 4932 | warn( |
| 4933 | ("\"" + hyphenatedKey + "\" is a reserved attribute and cannot be used as component prop."), |
| 4934 | vm |
| 4935 | ); |
| 4936 | } |
| 4937 | //通过defineProperty的set方法去通知notify()订阅者subscribers有新的值修改 |
| 4938 | defineReactive(props, key, value, function () { |
| 4939 | if (vm.$parent && !isUpdatingChildComponent) { |
| 4940 | warn( |
| 4941 | "Avoid mutating a prop directly since the value will be " + |
| 4942 | "overwritten whenever the parent component re-renders. " + |
| 4943 | "Instead, use a data or computed property based on the prop's " + |
| 4944 | "value. Prop being mutated: \"" + key + "\"", |
| 4945 | vm |
| 4946 | ); |
| 4947 | } |
| 4948 | }); |
| 4949 | } |
| 4950 | // static props are already proxied on the component's prototype |
| 4951 | // during Vue.extend(). We only need to proxy props defined at |
no test coverage detected