首页 > 代码库 > props 父向子组件传参

props 父向子组件传参

parent.vue 父

<template>
 <div class="wapper">
     <child message="hello!"></child>
</div>
</template>

 <script>
import child from ../components/child
 export default {
  name:wapper,
  components:{child}
 }
 </script>

child.vue子

 <template>
    <div @click="up">点我</div>
</template>

<script>
  export default{
    data(){
      return {
        msg: 请输入值
      }
    },
    props:[message],
    methods: {
     up() {
       console.log(this.message)
    }
    }
  }
</script>

结果:

hello

props 父向子组件传参