![](/img/trans.png)
[英]how can i display the extracted json data on my webpage using a bootsrap card after pulling it from an external api
[英]how to display data extracted from other website onto my html webpage using vuejs
我想顯示從 API 網站中提取的數據,我可以在控制台中顯示,但無法在網頁上顯示。 誰能幫我解決這個問題? 我正在嘗試僅顯示卧室燈光狀態數據中的 id 元素。
const importdata = new Vue ({
el: '#importdata',
data() {
return {
status:[]
}
},
methods: {
getStatus() {
fetch('https://a13.sglms.com.my/sglms/api/ios/19/')
.then(response => response.json())
.then(data => this.status = data)
}
}
});
這是我的標記
<html>
<head>
<title>on off</title>
<script src="cdn.jsdelivr.net/npm/vue/dist/vue.js" defer></script>
<script src="sglmsvue.js" defer></script>
</head>
<body>
<div id="importdata">
<div v-for="s in status" :key="s.id">
<h1>{{s.id}}</h1>
</div>
</div>
</body>
</html>
如果您要獲取的響應是url那么status
屬性不是列表,它是 object 並且您不能在 for 循環中使用它,您可以 Z9516DFB15F51C7EE15F51C7EE15F51C7EE19A4D46B8C0
methods: {
getStatus() {
fetch('https://a13.sglms.com.my/sglms/api/ios/19/')
.then(response => response.json())
.then(data => this.status.push(data))
}
已解決,html網頁無法顯示的原因是因為掛載的function沒有在下面的方法中添加。
聲明:本站的技術帖子網頁,遵循CC BY-SA 4.0協議,如果您需要轉載,請注明本站網址或者原文地址。任何問題請咨詢:yoyou2525@163.com.