1.父组件
<template> <div> <subcomponent :subdata="data"></subcomponent> </div> </template> <script> import subcomponent from './subcomponent' export default { name: 'parentComponent', components:{ 'subcomponent':subcomponent }, data (){ return{ data:'' } } } </script>
2.子组件
<script> export default { name: 'subcomponent', props: ['subData'], data (){ return{} }, watch:{ subdata:'showData' }, methods:{ showData(){ alert(this.subdata); } } } </script>
其它:命名方式存疑