Created
April 12, 2018 04:31
-
-
Save milkmidi/5794e67c2611a7d34feef6e8aea6f2e0 to your computer and use it in GitHub Desktop.
JS Bin // source https://jsbin.com/zahirutuhe
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
<!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> |
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
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