🗒️上传文件

<input type="file" accept="image/jpeg,image/jpg,image/png" @change="fileChange">
return new Promise((resolve, reject) => {
    let formData = new FormData()
    formData.append('file', e.target.files[i]) // 之前会校验文件的大小、类型

    const instance = axios.create()
    instance.defaults.withCredentials = false
    
    instance.post(url, formData)
            .then(res => {
                if(res.status==200 && res.data.errno==0){
                    resolve(res.data)
                } else {
                    reject(res.data)
                }
            }).catch(err => {
                reject(err)
            })
})

Last updated