Skip to content

Instantly share code, notes, and snippets.

@milkmidi
Created April 12, 2018 04:31
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save milkmidi/5794e67c2611a7d34feef6e8aea6f2e0 to your computer and use it in GitHub Desktop.
Save milkmidi/5794e67c2611a7d34feef6e8aea6f2e0 to your computer and use it in GitHub Desktop.
JS Bin // source https://jsbin.com/zahirutuhe
<!DOCTYPE html>
<html>
<head>
<meta charset="utf-8">
<meta name="viewport" content="width=device-width">
<title>JS Bin</title>
<script src="https://cdnjs.cloudflare.com/ajax/libs/vue/2.5.16/vue.min.js"></script>
<script src="https://cdnjs.cloudflare.com/ajax/libs/vuex/3.0.1/vuex.min.js"></script>
</head>
<body>
<div id="app"></div>
<script id="jsbin-javascript">
const store = new Vuex.Store({
state: {
basic:{
age: 10,
sex: 'M'
}
}
})
Vue.component('childComponent', {
computed: {
age:{
set:function(value){
this.$store.state.basic.age = value;
},
get: function(){
return this.$store.state.basic.age;
}
}
},
methods:{
changeHandler:function(e){
this.age = e.target.value;
}
},
template: '<div><input :value="age" @input="changeHandler"></div>'
})
Vue.component('childComponent2', {
computed: {
age:{
get: function(){
return this.$store.state.basic.age;
}
}
},
template: '<div>{{age}}</div>'
})
var vm = new Vue({
el:'#app',
store:store,
template: "<div><h1>hi</h1><childComponent/><childComponent2/></div>"
});
</script>
<script id="jsbin-source-javascript" type="text/javascript">const store = new Vuex.Store({
state: {
basic:{
age: 10,
sex: 'M'
}
}
})
Vue.component('childComponent', {
computed: {
age:{
set:function(value){
this.$store.state.basic.age = value;
},
get: function(){
return this.$store.state.basic.age;
}
}
},
methods:{
changeHandler:function(e){
this.age = e.target.value;
}
},
template: '<div><input :value="age" @input="changeHandler"></div>'
})
Vue.component('childComponent2', {
computed: {
age:{
get: function(){
return this.$store.state.basic.age;
}
}
},
template: '<div>{{age}}</div>'
})
var vm = new Vue({
el:'#app',
store:store,
template: "<div><h1>hi</h1><childComponent/><childComponent2/></div>"
});
</script></body>
</html>
const store = new Vuex.Store({
state: {
basic:{
age: 10,
sex: 'M'
}
}
})
Vue.component('childComponent', {
computed: {
age:{
set:function(value){
this.$store.state.basic.age = value;
},
get: function(){
return this.$store.state.basic.age;
}
}
},
methods:{
changeHandler:function(e){
this.age = e.target.value;
}
},
template: '<div><input :value="age" @input="changeHandler"></div>'
})
Vue.component('childComponent2', {
computed: {
age:{
get: function(){
return this.$store.state.basic.age;
}
}
},
template: '<div>{{age}}</div>'
})
var vm = new Vue({
el:'#app',
store:store,
template: "<div><h1>hi</h1><childComponent/><childComponent2/></div>"
});
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment