父子組建通訊程式碼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) //提交一個物件給父元件
},