<!DOCTYPE html>
<html>
<head>
<meta charset="UTF-8">
<title>组件之间的通信--父往子传值(可自动触发)</title>
<script src="https://cdn.jsdelivr.net/npm/[email protected]/dist/vue.js"></script>
</head>
<body>
<div id="app">
父子组件嵌套
<father></father>
</div>
<template id="father">
<div>
我是父组件:{
{msg}}
<son :mm="data1" ></son><!--父组件往子组件里边传值-->
</div>
</template>
<template id="son">
<div>
我是子组件:{
{mm}}
</div>
</template>
<script>
let vm = new Vue({
el: '#app',
components: {
'father': {
template: '#father',
data() {
return {
msg: '测试父组件内容',
data1:'来源于父组件的数据'
}
},
components: {
'son': {
template: '#son',
props:['mm']//子组件声明且接值
}
}
}
}
});
</script>
</body>
</html>
vue10--组件之间的通信--父往子传值(可自动触发)
猜你喜欢
转载自blog.csdn.net/gcyqweasd/article/details/113799105
今日推荐
周排行