vue 父子组件传递参数

父组件

<style>
</style>
<template>
  <div>
    <div>父组件</div>
    <child
      width='200'
      :message="parentMsg"
      @funA="selectFunc"
    ></child>
  </div>
</template>

<script>
  import child from './searchB'
  export default {
    components: {
      child
    },
    data() {
      return {
        parentMsg: 'aaaa parent'  //在data中定义需要传入的值
      }
    },
    methods: {
      selectFunc(value) {
        console.log(value)

      }
    },
    mounted() {

    },


  }
</script>

子组件

<style>

</style>
<template>
  <div class="searchZJ">
    <button @click="box">修改父数据</button>
    <div>{{message}}(子组件)</div>
  </div>
</template>

<script type="text/ecmascript-6">
  export default {
    props: {
      width: String,
      message: String,
    },
    data() {
      return {

      }
    },
    methods: {
      box(){
        this.$emit('funA', 33333)
      },
      logmsg(){
        console.log("B+++++"+this.message);
      }
    },
    mounted() {
      this.logmsg()
    },
  }
</script>


猜你喜欢

转载自blog.csdn.net/guohao326/article/details/85262536