[英][Unhandled promise rejection: TypeError: undefined is not an object (evaluating 'response.data')]
[英]Unhandled Promise Rejection TypeError undefined is not an object (evaluating services drugSearchService getDrugsByCriteria(criteria, val).then)
DrugSearchService.js
import axios from "axios";
const DRUG_GENERIC_API_URL ='http://localhost:8080/drug/search/generic/'
const DRUG_MAIN_API_URL ='http://localhost:8080/drug/search/main/'
class DrugSearchService{
getDrugsByCriteria(criteria,val){
if(criteria == 'Main'){
return axios.get(DRUG_MAIN_API_URL+val);
}else if(criteria == 'Generic'){
return axios.get(DRUG_GENERIC_API_URL+val);
}
}
}
export default new DrugSearchService()
药物搜索.vue
<template>
<div class="input-group">
<input v-model="val" type="text">
<select v-model="criteria">
<option value="Main" selected>Main Name</option>
<option value="Generic">Generic Name</option>
</select>
<button type="submit" v-on:click="get_Drugs_by_criteria()">Search</button>
</div>
</template>
<script>
import drugSearchService from '@/services/drugSearchService';
export default{
name:'Drugs_by_criteria',
data(){
return{
criteria:'',
val : '',
drugsByCriteria:[]
}
},
methods:{
get_Drugs_by_criteria(){
// drugSearchService.getDrugsByCriteria(this.criteria,this.val).then((response)=>{
drugSearchService.getDrugsByCriteria('Main','Loratadine').then((response)=>{
this.drugsByCriteria = response.data;
});
}
},
created(){
this.get_Drugs_by_criteria()
}
}
错误:未处理的 Promise 拒绝:类型错误:未定义不是 object(评估' services_drugSearchService__WEBPACK_IMPORTED_MODULE_0 _["default"].getDrugsByCriteria(this.criteria').val
想这样使用
drugSearchService.getDrugsByCriteria(this.criteria,this.val).then((response)=>{
但得到错误。 但与 static 数据相同的方法正在工作。
像这样
drugSearchService.getDrugsByCriteria('Main','Loratadine').then((response)=>{
这有什么问题
drugSearchService.getDrugsByCriteria(this.criteria,this.val).then((response)=>{
我用一些值初始化了标准和 val。 及其现在的工作。
data(){
return{
criteria:'Main',
val : 'Metformin',
drugsByCriteria:[]
}
},
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.