【问题标题】:Axios get params array is converting to stringaxios 获取参数数组正在转换为字符串
【发布时间】:2020-05-10 08:00:50
【问题描述】:

Axios

    var datas=[{"ticket_no": "1","details": "detail1"}];
    instance.get(`somepath`, {
        params: ({
            data:datas,
        }),
        responseType: 'blob',Accept: 'application/pdf',
        }).then((response) => {
            const file = new Blob(
                [response.data], 
                {type: 'application/pdf'});
            const fileURL = URL.createObjectURL(file);
            //Open the URL on new Window
            window.open(fileURL);

        }).catch((error) => {
            console.log(error)
        }).finally(() => {
        })

PDF.test

{{data}}

//返回“{ticket_no:1,details:detail1}” //不是数组而是字符串

【问题讨论】:

    标签: laravel axios


    【解决方案1】:

    var datas=[{"ticket_no": "1","details": "detail1"}]; instance.get(somepath, { 参数:({ 数据:JSON.stringify(数据), }), responseType:'blob',接受:'application/pdf', }).then((响应) => { 常量文件 = 新的 Blob( [response.data], {类型:'应用程序/pdf'}); const fileURL = URL.createObjectURL(file); //在新窗口打开网址 window.open(fileURL);

        }).catch((error) => {
            console.log(error)
        }).finally(() => {
        })
    

    //控制器

        $pdf = PDF::loadView('PDF.pdf_irregularity',['data' => json_decode($request->data)])->setPaper('A5', 'landscape');
        $fileName = 'Irregulairty';
        return $pdf->output();
    

    【讨论】:

      猜你喜欢
      • 2021-11-20
      • 1970-01-01
      • 1970-01-01
      • 2012-04-30
      • 1970-01-01
      • 1970-01-01
      • 2021-02-25
      • 2017-11-27
      相关资源
      最近更新 更多