Vue父组件向子组件传递参数

1、父组件projectBatchsindex.vue

// 使用:projectId="this.projectId" 传递参数
<ProjectBatchEdit ref="projectBatchEdit" :projectId="this.projectId" @on-update="search"></ProjectBatchEdit>
import ProjectBatchEdit from 'pages/projectBatch/projectBatchEdit'

2、子组件projectBatchEdit.vue

export default {
  props: {
    projectId: Number    // 接受值并定义传递值类型
  }
}

3、子组件的方法中获取值,触发事件,打debbug查看t或者this.projectId的值确定是否传递成功

    // 添加方法
    handlerAdd () {
      debugger
      let t = this.projectId
    }

猜你喜欢

转载自blog.csdn.net/weixin_41996632/article/details/89532428