This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
vm[key] = methods[key].bind(vm); |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
/** | |
* Simple bind polyfill for environments that do not support it, | |
* e.g., PhantomJS 1.x. Technically, we don't need this anymore | |
* since native bind is now performant enough in most browsers. | |
* But removing it would mean breaking code that was able to run in | |
* PhantomJS 1.x, so this must be kept for backward compatibility. | |
*/ | |
/* istanbul ignore next */ | |
function polyfillBind (fn: Function, ctx: Object): Function { |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
function initMethods (vm: Component, methods: Object) { | |
const props = vm.$options.props | |
for (const key in methods) { | |
if (process.env.NODE_ENV !== 'production') { | |
if (typeof methods[key] !== 'function') { | |
warn( | |
`Method "${key}" has type "${typeof methods[key]}" in the component definition. ` + | |
`Did you reference the function correctly?`, | |
vm | |
) |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
import { initMixin } from './init' | |
import { stateMixin } from './state' | |
import { renderMixin } from './render' | |
import { eventsMixin } from './events' | |
import { lifecycleMixin } from './lifecycle' | |
import { warn } from '../util/index' | |
function Vue (options) { | |
if (process.env.NODE_ENV !== 'production' && | |
!(this instanceof Vue) |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
app.methods.increment(); // TypeError: Cannot read property 'increment' of undefined | |
app.increment(); // Properly works |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
let app = new Vue({ | |
el: '#counterApp', | |
data() { | |
return { | |
counter: 0 | |
} | |
}, | |
methods: { | |
increment() { | |
this.counter++; |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
<div id="counterApp"> | |
<div> | |
Our counter value is: {{counter}} | |
</div> | |
<button @click="increment">Click Me</button> | |
</div> |