uploader在多組件中傳參index,方便val賦值(由服務器返回的url地址)ios
template:
<van-uploader :after-read="afterRead(itm)" v-model="itm.imgs" :max-count="maxImgCount" :disabled="disabled" ></van-uploader>
js:itm是傳入進來的,方便val賦值。file是after-read 文件讀取完成後的回調函數所帶的默認參數axios
afterRead(itm) { return file => { this.$toast.loading({ duration: 0 }); this.axios({ method: "post", url: "/api/Upload/List", data: JSON.stringify({ Id: file.content }) }) .then(({ code, data, msg }) => { this.$toast.clear(); if (code >= 0) { var imgs = itm.imgs || []; var i = imgs.length; if (i <= 0) { imgs = [{ url: data }]; } else { imgs[i - 1] = { url: data }; } itm.imgs = imgs; var url = []; for (const row of imgs) { url.push(row.url); } itm.Val = url.join(","); } else { this.$toast(msg); } }) .catch(err => { this.$toast.clear(); this.$toast(`${err}`); }); }; }