【发布时间】:2019-10-14 11:35:27
【问题描述】:
我正在使用 Vuetify 表单验证来检查输入字段,并且我正在尝试确定是否可以调用 ajax get 调用并使其等待,以便我可以在规则中使用结果?
我在下面尝试过,但它似乎不起作用!
export default {
data() {
return {
rules: {
isLocationNew: value => {
if (value == '' || value == null || value.length <= 1) {
this.validLocation = false;
return 'Invalid length.';
}
this.validLocation = true;
var hasName = this.newLocationNameSearch(value);
if (hasName) {
return 'Location name already exists.';
} else {
return true;
}
}
},
// down in methods
methods: {
async newLocationNameSearch(text) {
if (text == '' || text == null || text.length <= 1) {
return false;
}
await axios.get('/api/Locations/HasLocationName', {
params: {
text: text,
jobsiteId: this.jobsiteId
}
}).then(response => {
return response.data;
}).catch(function(error) {
console.log(error)
})
}
}
【问题讨论】:
标签: javascript ajax vue.js axios vuetify.js