Skip to content

Instantly share code, notes, and snippets.

@nasum
Last active August 26, 2015 03:43
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 nasum/26b2f21a272e9803955d to your computer and use it in GitHub Desktop.
Save nasum/26b2f21a272e9803955d to your computer and use it in GitHub Desktop.
Vue.jsで親ViewModelにcomponentをぶら下げてデータを共有 ref: http://qiita.com/tomato360/items/1244cb44c832dda7f7d5
<h1>Component Test</h1>
<div class="main">
{{title}}
<my-component-one data="{{$data}}"></my-component-one>
<my-component-two data="{{$data}}"></my-component-two>
<button v-on="click:output">
check
</button>
</div>
<div class="output">
</div>
<my-component></my-component>
var dataModel = {
title: "Title",
one: "component1",
two: "component2"
};
var MyComponent_one = Vue.extend({
template: '<p v-on="click:rewrite">{{data.one}}</p>',
props: ['data'],
methods:{
rewrite: function(){
this.data.one = "rewrite";
}
}
});
var MyComponent_two = Vue.extend({
template: '<p v-on="click:rewrite">{{data.two}}</p>',
props: ['data'],
methods:{
rewrite: function(){
this.data.two = "rewrite";
}
}
});
var mainViewModel = new Vue({
el: ".main",
data: dataModel,
methods: {
output: function(){
$('.output').html(this.$data.one + " " + this.$data.two);
}
},
components: {
"my-component-one": MyComponent_one,
"my-component-two": MyComponent_two
}
});
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment