我需要将附加的JSON文件转换为以下格式article.source,article.authors.map(a => a.name))。join(',')},以便可以在VUE项目中使用它。
我从API调用中获取了
new Vue({
el: '#app',
data () {
return {
info: null
}
},
mounted () {
axios({
method: "GET",
url: "https://eutils.ncbi.nlm.nih.gov/entrez/eutils/esummary.fcgi?db=pubmed&retmode=json&rettype=abstract&id=28198679"
}).then(res => {
var obj = res.data.result;
delete obj.uids;
console.log("1");
console.log(obj);
this.articles = obj;
console.log("2");
console.log(this.articles);
console.log("3");
console.log("next");
console.log(JSON.stringify(this.articles));
let data = JSON.stringify(this.articles);
console.log("4");
var json = JSON.parse(data);
console.log("5");
alert(json["source"]);
}).catch(error => {
//handle error
console.log("Error");
});
}
})
<!DOCTYPE html>
<html lang="en">
<head>
<meta charset="utf-8">
<meta name="viewport" content="width=device-width, initial-scale=1, shrink-to-fit=no">
<meta name="description" content="">
<meta name="author" content="">
<title>Axios</title>
<script src="https://cdn.jsdelivr.net/npm/vue@2.6.10/dist/vue.js"></script>
<script src="https://unpkg.com/axios/dist/axios.min.js"></script>
<script src="app.js"></script>
</head>
<body>
<div id="app">
{{ info }}
</div>
</body>
</html>
我已经尝试过做,但是我是vue的新手,所以对我来说,有几个方法可以做是很好的学徒制