dark版

vue中利用axios实现文件上传进度实时更新

var form = new FormData()
    form.append('file', vm.$refs.upload.files[0])
    form.append('id', id)
    form.append('type', type)
    var config = {
        // 进度
        onUploadProgress: progressEvent => {
            var complete = (progressEvent.loaded / progressEvent.total * 100 | 0) + '%'
            this.progress = complete
        }
    }
    axios.post(`api/uploadFile`,
        form, config).then((res) => {
        if (res.data.status === 'success') {
            console.log('上传成功')
        }
    })