【发布时间】:2019-03-12 21:59:57
【问题描述】:
我使用 PHP 创建了我的 API,链接如下:https://monstajams.co/streaming/rest/api/album/read.php
但是每当我使用 axios 将其放入我的 Vue.js (Home.vue) 文件中时,前端都不会显示任何数据。
下面是我的代码:
<ul class="ta-track-list" v-if="faqs && faqs.length">
<li class="ta-track-card column col-2 flex-column" v-for="faq of faqs">
<div class="inner">
<div class="artwork" role="link">
<span role="link" style="background-image: url(http://localhost/mymusic/assets/images/artwork/Wizkid-Soco.jpg);">
</span>
<div class="hover flex align-center justify-center">
<button id="webutton" class="ta-secondary play" onclick='playSong()'>
<i class="material-icons">play_arrow</i>
</button>
</div>
</div>
<div class="info">
<div class="title white-primary-hover" role="lin">{{ faqs }}</div>
<div class="username light-white-hover" role="link">{{ faq.artist }}</div>
<div class="released">{{ faq.duration }}</div>
</div>
</div>
</li>
</ul>
<script>
import axios from 'axios';
export default {
name: 'home',
data: () =>({
faqs: [],
errors: []
}),
created() {
axios.get('https://monstajams.co/streaming/rest/api/album/read')
.then(response => {
this.faqs = response.data;
})
.catch(e => {
this.errors.push(e)
})
}
}
</script>
【问题讨论】:
-
您能告诉我们您的组件数据是如何构成的吗?
-
如果你的 vue 应用在本地主机上,它必须是 CORS
-
内部 catch(e) - 你能 console.log out e 吗?
-
@darklightcode 我的标题 // 标题 header('Access-Control-Allow-Origin: *'); header('Content-Type: application/json');
-
@darklightcode 看起来不像 CORS 问题 - codesandbox.io/s/…
标签: javascript php html vue.js