父组件向子组件传值的方法很简单,就一句话。vue父组件向子组件传值的方法:必须使用props属性来定义父组件传递过来的数据,然后把父组件里的数据传递到子组件中就行了。
1.请看下面这个例子,你就懂了
<!Doctype html>
<html>
<head>
<meta http-equiv="Content-Type" content="text/html; charset=GBK"/>
<title>vue父组件向子组件传值方法</title>
</head>
<body>
<div id="app">
<son :finfo="msg"></son>
</div>
<script src="https://cdn.jsdelivr.net/npm/vue"></script>
<script>
var vm = new Vue({
el: '#app',
data: {
msg: '我是父组件里的消息'
},
components: {
son: {
template: '<h1>我是子组件 --- {{finfo}}</h1>',
props: ['finfo']
}
}
});
</script>
</body>
</html>
2.结果如下: