天天看点

vue 动态父组件传值给子组件

父组件

先在父组件引入子组件

import liChart from './dashboard/liChart';
components: { pieChart,linesChart,piesChart,piChart,liChart },
           
<div class="block">
    <el-date-picker
      v-model="month"
      type="month"
      placeholder="选择月"
      value-format="MM"
      @change="getSTime">
    </el-date-picker>
</div>
<li-Chart :msg ="this.month" >
</li-Chart>
           
getSTime(val) {
      this.month = val   
      console.log('222',this.month)
},
           

子组件通过props接受参数

props: {
    msg:{
      type: String,
    }
}
watch: {
      msg(newval,oldval){
        this.msg = newval
        console.log(333,this.msg)
      }
},
           
vue