1父组件和子组件之间的传递信息
<!DOCTYPE html>
<html>
<head>
<meta charset="UTF-8">
<title></title>
</head>
<style>
.red{width:200px;height:300px;background:red;}
.green{width:200px;height:300px;background:green;}
</style>
<body>
<div id="app">
<button v-on:click="color" v-bind:value="c">改变颜色</button>//设置一个value=c用来设置改变父组件的某一个属性
<child v-bind:class="c"></child>//子组件中绑定一个class=c来获取到点击改变的父组件的值来改变子组件的class的值
</div>
<script src="js/vue.js"></script>
<script>
Vue.component(‘child‘,{//注册一个组件
template:‘<div></div>‘,
})
new Vue({
el:"#app",
data:{
c:"red"
},
methods:{
color:function(){
this.c=this.c=="red"?"green":"red"
}
}
})
</script>
</body>
</html>
原文:http://www.cnblogs.com/GainLoss/p/6541981.html