vue.js 请求的URL太长返回错误414

uemypmqf  于 2022-12-14  发布在  Vue.js
关注(0)|答案(1)|浏览(372)

我正在使用vuejs并向服务器发出axios请求以下载csv。

download() {
        var that = this
        //this.records = [{id: 1, name: 'Jack'}, {id: 2, name: 'Jacky'}, {id: 3, name: 'Jackie'}.....100s]
        //this.header = [{value: 'id', text: 'ID'}, {value: 'name', text: 'Name'}]
        var headers = this.header.map(a => a.text);
        var url = USERS_REPORT_DOWNLOAD_URL + '?';
        this.$axios.get(url, { params: { users: this.records, headers: headers}, responseType: 'blob' })
            .then(response => {
                 var file = new Blob([response.data]);
                 FileSaver.saveAs(file, 'users ' + moment().format('MMMM Do YYYY, hh-mm a') + '.xls');
            });
}

调用此方法时,返回HTTP Error 414 - The request URL is too long。可能是因为参数太长。请帮助我解决此问题。

5lhxktic

5lhxktic1#

download() {
            var that = this
            //this.records = [{id: 1, name: 'Jack'}, {id: 2, name: 'Jacky'}, {id: 3, name: 'Jackie'}.....100s]
            //this.header = [{value: 'id', text: 'ID'}, {value: 'name', text: 'Name'}]
            var headers = this.header.map(a => a.text);
            var url = USERS_REPORT_DOWNLOAD_URL + '?';
            let postConfig = {
             responseType: 'blob',
            }
            this.$axios.post(url, { users: this.records, headers: headers }, postConfig)
                .then(response => {
                     var file = new Blob([response.data]);
                     FileSaver.saveAs(file, 'users ' + moment().format('MMMM Do YYYY, hh-mm a') + '.xls');
                });
}

相关问题