如何使用axios获取来自api的数据。我需要将datas变量传递给doc.autoTable函数。我没有从axios调用获取数据。我需要使用api数据生成pdf。
exportpdf(){
var self = this;
axios.get("http://34.67.88.0:3000/api/env/fdsfsdf")
.then(function(res){
self.datas = res.data[0];
})
let columns = [
{title:"Time",dataKey:"time"},
{title:"Temperature",dataKey:"Temperature"},
{title:"Humidity",dataKey:"Humidity"}
];
var doc = new jsPDF('p','pt');
doc.autoTable(columns,self.datas);
doc.save("p.pdf");
}
below is my api data
[
{
"Humidity": "70.50",
"Temperature": "25.50",
"time": "2019-08-28T10:04:22.597533952Z"
},
{
"Humidity": "70.50",
"Temperature": "25.40",
"time": "2019-08-28T10:09:23.709048064Z"
},
{
"Humidity": "70.50",
"Temperature": "25.40",
"time": "2019-08-28T10:14:25.430288128Z"
}
]