本文实例为大家分享了vue的props实现父组件变化子组件一起变化,供大家参考,具体内容如下
类似于用 v-bind 绑定 HTML 特性到一个表达式,也可以用 v-bind 绑定动态 Props 到父组件的数据。每当父组件的数据变化时,也会传导给子组件:
<div> <input> <br> <child></child> </div>
使用 v-bind 的缩写语法通常更简单:
实例:
html>
<script></script>
<meta>
<title>vue的props实现父组件变化子组件一起变化</title>
<div>
<input> <!--input绑定实例中data中的message-->
<div>
<child></child> <!--子组件绑定实例中data中的message-->
</div>
</div>
<script>
Vue.config.debug = true;
Vue.component('child',{
props: ['myMessage'], //VUE实例中myMessage 等价于my-message
template: '<span>{{ myMessage }}<br>'
});
var vm = new Vue({
el: '#app1',
data:{
messsage:'hello you are a good boy!'
}
});
</script>
前端入门到VUE实战笔记:立即使用
在学习笔记中,你将探索 前端 的入门与实战技巧!











