//258 state.js function initMethods (vm: Component,methods: Object){ const props = vm.$options.props for (const key in methods){ if (methods[key] == null) { warn( `Method "${key}" has an undefined value in the component definition. ` + `Did you reference the function correctly?`, vm ) } if(props && hasOwn(props, key) ){ warn(`Method "${key}" has already been defined as a prop.`, vm) //props = [] 嗯 知道了不能props 和 methods的方法名不能同时存在,就是我平时组件的时候 //可以this.method吧 而不是像data那样 this.$data.data (冲突的时候的话,嘛我猜的,到时候看到这就OK了) } if((key in vm) && isReserved(key)){ warn( `Method "${key}" conflicts with an existing Vue instance method. ` + `Avoid defining component methods that start with _ or $.` ) //不能定义vue自带的方法 } vm[key] = bind(methods[key], vm) //你传进来的options.methods的方法,this就被绑定在这个vue实例上了 } }
//core/util/env.js 37 // this needs to be lazy-evaled because vue may be required before // vue-server-renderer can set VUE_ENV /*const VueSSRServerPlugin = require('vue-server-renderer/server-plugin') 在webpack.server.js 当作一个插件 生成server.json 可以去看SSR文章 */ let _isServer exportconst isServerRendering = () => { if (_isServer === undefined) { /* istanbul ignore if */ if (!inBrowser && !inWeex && typeof global !== 'undefined') { // detect presence of vue-server-renderer and avoid // Webpack shimming the process _isServer = global['process'].env.VUE_ENV === 'server' } else { _isServer = false } } return _isServer }
lang
1 2 3 4
exportfunctionisReserved (str: string): boolean{ const c = (str + '').charCodeAt(0) //utf-16 编码 return c === 0x24 || c === 0x5F// $ 36 0044 0x24 ; _ 95 0137 0x5f }