<template>
<div>
<h1>{{ searchWord(rawString) }}</h1>
</div>
</template>
<script>
import axios from 'axios';
export default {
methods: {
searchWord(rawString) {
const splitRawString = rawString.match(/^(\w\w\w)\d/);
if (splitRawString) {
// If regex found a match
return axios
.get(`https://www.url.com/path/${splitRawString[1]}`)
.then(response => {
return response.data;
})
.catch(error => error);
}
}
}
};
</script>
在上面的示例中,我试图输出axios promise的结果。
不幸的是,<h1>
标签的内容是:[object Promise]
如果我使用console.log(response.data)
;而不是return response.data
,它可以工作。