//index.vue img1:<uploadArea ref="upload1" :url="url"/>
img2:<uploadArea ref="upload2" :url="url"/>
<button @click="submit">上傳</button>//提交圖片的http地址async submit () { let imgs1 = await this.$refs.upload1.uploadPic(); let imgs2 = await this.$refs.upload2.uploadPic();
console.log(imgs1[0])
}//uploadImg.vue 圖片上傳組件uploadPic() { //...
return imgs //通過ajax獲取上傳圖片的本地地址換取對應(yīng)的http地址,然后返回出來}流程是首先點擊提交按鈕觸發(fā)submit方法執(zhí)行子組件的uploadPic方法,把本地的圖片上傳獲取到http鏈接,然后執(zhí)行submit下邊的代碼提交這個表單。因為uploadImg.vue是通用組件所以他不能涉及業(yè)務(wù)邏輯。項目中所有圖片上傳都用的是uploadImg.vue這個組件,但是有的頁面是有多個用到圖片上傳組件的地方,我試了一下通過return無法將imgs傳到index頁面,還有什么方法可以解決這個問題?
vue 父組件 調(diào)用子組件的方法并return數(shù)據(jù)獲取不到?
慕桂英4014372
2018-10-24 09:35:39