Skip to content

Instantly share code, notes, and snippets.

vm[key] = methods[key].bind(vm);
/**
* 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 {
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
)
@tdondich
tdondich / index.js
Created May 13, 2019 03:07
Vue.JS Starting File
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)
app.methods.increment(); // TypeError: Cannot read property 'increment' of undefined
app.increment(); // Properly works
let app = new Vue({
el: '#counterApp',
data() {
return {
counter: 0
}
},
methods: {
increment() {
this.counter++;
@tdondich
tdondich / counter.html
Created May 13, 2019 02:44
Simple Vue.js counter application html
<div id="counterApp">
<div>
Our counter value is: {{counter}}
</div>
<button @click="increment">Click Me</button>
</div>