Last active
March 5, 2018 13:21
-
-
Save meredevelopment/625b1884fe882edf573e2df289d936cb to your computer and use it in GitHub Desktop.
Benjamin doesn't understand scope...
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
<template> | |
<div id="app"> | |
<ComponentOne/> | |
</div> | |
</template> | |
<script> | |
import {store} from './store.js' | |
import ComponentOne from './ComponentOne' | |
export default { | |
name: 'App', | |
data: function () { | |
return { | |
sharedState: store.state | |
} | |
}, | |
components: { | |
ComponentOne, | |
}, | |
} | |
</script> | |
<style> | |
#app { | |
font-family: 'Avenir', Helvetica, Arial, sans-serif; | |
-webkit-font-smoothing: antialiased; | |
-moz-osx-font-smoothing: grayscale; | |
text-align: center; | |
color: #2c3e50; | |
margin-top: 60px; | |
} | |
</style> |
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
<template> | |
<div> | |
<h2>{{ sharedState.msg }}</h2> | |
<input type="button" value="Set sharedState.msg" v-on:click.prevent="sharedState.msg = 'Message set directly from first button'"> | |
<input type="button" value="Fire storeFunctionMethod" v-on:click.prevent="storeFunctionMethod('Message set from second button via storeFunctionMethod')"> | |
<input type="button" value="Fire store.storeFunction" v-on:click.prevent="store.storeFunction('Message set from third button via store.storeFunction')"> | |
</div> | |
</template> | |
<script> | |
import {store} from './store.js' | |
export default { | |
name: 'ComponentOne', | |
data(){ | |
return { | |
sharedState: store.state | |
} | |
}, | |
methods: { | |
storeFunctionMethod(val) { | |
store.storeFunction(val) | |
} | |
}, | |
mounted() { | |
store.storeFunction("Message set when ComponentOne mounted") | |
} | |
} | |
</script> | |
<style> | |
</style> |
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 Vue from 'vue' | |
import App from './App' | |
import {store} from './store.js' | |
Vue.config.productionTip = true | |
new Vue({ | |
el: '#app', | |
components: { | |
App | |
}, | |
data: { | |
sharedState: store.state | |
}, | |
template: '<App/>' | |
}) |
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
export const store = { | |
state: { | |
msg: '', | |
}, | |
storeFunction: function (inp) { | |
console.log("Fired storeFunction: "+inp) | |
this.state.msg = inp | |
} | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment