我正在玩 vueJS 和 rapidapi,我正在尝试使用 vue 显示来自 API 的数据并使用 JS Fetch 方法检索 API。但是,当我运行代码时,我得到的只是启动它的值(即:[])。
<template>
<div>
<div>{{ chuckData }}</div>
</div>
</template>
<script>
var chuck = [];
fetch("https://matchilling-chuck-norris-jokes-v1.p.rapidapi.com/jokes/random", {
method: "GET",
headers: {
"x-rapidapi-host": "matchilling-chuck-norris-jokes-v1.p.rapidapi.com",
"x-rapidapi-key": "***"
}
})
.then(response => response.json()) // Getting the actual response data
.then(data => {
chuck = data;
})
.catch(err => {
console.log(err);
});
export default {
data() {
return {
chuckData: chuck
};
}
};
</script>
我还尝试使用以下内容:
var chuck fetch("https://matchilling-chuck-norris-jokes-v1.p.rapidapi.com/jokes/random", {...}
但我得到的只是 [object Promise] 没有我期望显示的数据。
我究竟做错了什么?