Vue父子组件传值
<!doctype html><html lang="en">
<head>
<meta charset="UTF-8">
<meta name="viewport"
content="width=device-width, user-scalable=no, initial-scale=1.0, maximum-scale=1.0, minimum-scale=1.0">
<meta http-equiv="X-UA-Compatible" content="ie=edge">
<title>父子组件通信</title>
<script src="../js/vue.js"></script>
<script src="../js/vue-router.js"></script>
</head>
<body>
<div id="app">
<my_div message="HelloWorld! -> 小米8" imgsrc="../img/01.jpg"></my_div>
<my_div message="HelloWorld! -> 红米6" imgsrc="../img/02.jpg"></my_div>
</div>
<!-- 子组件模板 -->
<template id="my_div">
<div>
<h1>{{ message }}</h1>
<!-- !注意:S6的语法不能使用驼峰体,否则内容不显示 -->
<img :src="imgsrc" height="340" width="632"/>
</div>
</template>
<script>
// 创建子组件构造器
Vue.component('my_div', {
template:'#my_div',
props: ['message', 'imgsrc']
});
// 创建Vue的实例
new Vue({
el: '#app',
})
</script>
</body>
</html>
以上是 Vue父子组件传值 的全部内容, 来源链接: utcz.com/z/375373.html