vue组件学习6(props传参)

来源:互联网 发布:百度域名注册服务费用 编辑:程序博客网 时间:2024/06/05 16:27
<!DOCTYPE html>
<html lang="en">
<head>
<meta charset="UTF-8">
<title>Document</title>
<script src="js/vue-1.0.24.debug.js"></script>
</head>
<body>
<div>
<child msg="hello_vue"></child>
</div>
<div style="margin-top:50px;">
<input type="text" v-model="inputMsg">
<br>
<children :input-msg="inputMsg"></children>
</div>
<script>
//1.父子组件props传参
Vue.component('child',{
props:['msg'],
template:'<span>{{msg}}</span>'
})
//2.props动态传参
Vue.component('children',{
props:['inputMsg'],
template:'<span>{{inputMsg}}</span>'
})
new Vue({
el:'body',
data:{
inputMsg:"hello_vue"
}
})
</script>
</body>

</html>

//例1:父子组件props进行传参,在绑定属性是直接写xxx=" ",

//例2:props动态传参,在绑定属性是v-on:xxx = "(v-model传的参数)"

原创粉丝点击