虽然相同的方法在另一个api调用中工作得很好,但是从这个api中提取会给我带来错误。错误读取Uncaught (in promise) TypeError: Cannot read properties of undefined (reading 'json')
我的提取代码如下:
import { ref } from "vue";
export default {
async setup() {
const prompProducts = ref(null);
const bc_prompProducts = await fetch(
"https://booking.hemantbhutanrealestate.com/api/v1/get_frontend_products"
);
prompProducts.value = await bc_prompProducts.json();
return {
prompProducts,
};
},
};
虽然相同的方法在我的其他api调用中没有错误,但是在这个api调用上会出现错误。请帮助,该网站已经在生产!
发布于 2022-06-28 05:47:01
您可以将异步调用放入函数并调用它,也可以使用onMounted
钩子:
const { ref, onMounted } = Vue
const app = Vue.createApp({
setup() {
const prompProducts = ref([]);
onMounted(async() => {
const bc_prompProducts = await fetch(
"https://booking.hemantbhutanrealestate.com/api/v1/get_frontend_products"
)
prompProducts.value = await bc_prompProducts.json()
})
return { prompProducts }
},
})
app.mount('#demo')
<script src="https://unpkg.com/vue@3/dist/vue.global.prod.js"></script>
<div id="demo">
<div v-for="pro in prompProducts" :key="pro.id">
<p>{{ pro }}</p>
</div>
</div>
https://stackoverflow.com/questions/72781021
复制相似问题