vue2父子组建传递数据

父子组建通信代码demo
父页面 父页面编写handleUploadNew 接收子组建uploadNew 传上来的对象
父页面传递tempUrl 给子页面初始化数据
<Upload :temp-url="tempUrl" @uploadNew="handleUploadNew" />

子组件里面




<i class="el-icon-delete" @click="rmImage" />

props: {
tempUrl: {
type: String,
default: ''
}
},

handleImageSuccess(data) {
  this.tempUrl = 'https://xxxx.cn/' + data.key
  this.file.url = this.tempUrl
  this.file.path = data.key
  this.$emit('uploadNew', this.file) //提交一个对象给父组件

},
posted @ 2024-08-11 00:19  yongliu  阅读(12)  评论(0)    收藏  举报