概述
父亲控件通过参数将数据传递给子控件
1.代码
<!DOCTYPE html>
<html>
<head>
<meta charset="utf-8">
<title>传参测试</title>
<script src="https://cdn.staticfile.org/vue/2.4.2/vue.min.js"></script>
</head>
<body>
<div id="app">
<parent-n></parent-n>
</div>
<script type="text/javascript">
// 注册
Vue.component('parent-n', {
template: '<child for-child-msg="aaa"></child>'
})
Vue.component('child',{
template: '<h1>{{forChildMsg}}</h1>',
props: ["for-child-msg"]
})
// 创建根实例
new Vue({
el: '#app'
})
</script>
</body>
</html>
2.运行结果
aaa