我想在发送API请求之前检查函数的返回值。
methods: {
................
................
................
save() {
if (this.editedIndex > -1) {
Object.assign(this.journals[this.editedIndex], this.editedItem)
console.log(checkItem(this.editedItem))
}
}
this.close()
},
checkItem(item) {
console.log(item.issn);
this.$http
.get("http://api.crossref.org/journals/"
+ item.issn
)
.then(response => {})
.catch(function (data) {
if (data.status === 404) {
console.log('it doesnt exists')
return true
}
if (data.status === 200) {
console.log('it exists')
return false
}
})
},
运行console.log(checkItem(this.editedItem))不会在控制台中返回任何布尔值,但是如果我在save方法中以checkItem(this.editedItem)的形式运行它,它将正确运行CheckItem。