get请求

let url = '后端接口地址'
window.location.href = url + '?id=' + id+ '&name=' + name + '&age=' + age

post请求

相对也比较简单,直接上代码。

 exportExcelObject(params, url) {
      const form = document.createElement('form');
      form.method = 'post';
      form.target = 'exportData';
      form.style.display = 'none';
      form.action = `${process.env.apiHost}${url}`;
      for (let key in params) {
        const input = document.createElement('input');
        input.type = 'hidden';
        input.name = key;
        input.value = params[key];
        form.appendChild(input);
      }
      const iframe = document.createElement('iframe');
      iframe.name = 'exportData';
      iframe.style.display = 'none';
      document.body.appendChild(form);
      document.body.appendChild(iframe);
      form.submit();
      setTimeout(() => {
        document.body.removeChild(form);
        document.body.removeChild(iframe);
      }, 3000);
      console.log('结束导出excel');
    }

  

01-07 12:58