【发布时间】:2018-08-30 10:53:43
【问题描述】:
我是新手,也许我在问简单的问题,但我没有找到答案。但我非常需要这个解决方案。我尝试使用 rest api 从 github repo 问题中获取数据,但我无法显示。我不知道为什么,我试图找到解决方案,但我没有找到正确的答案。
我的 Laravel Ilist.vue 文件:
<template>
<h1>List</h1>
<ul>
<li v-for="issue in info">
{{ issue.url }}:
</li>
</ul>
</template>
<script>
export default {
data () {
return {
info: null
}
},
mounted () {
axios
.get('https://api.github.com/repos/waffleio/waffle.io/issues')
.then((response) => {
console.log(response.data.bpi);
this.info = response.data.bpi;
})
}
}
</script>
但我只得到这个: enter image description here
我的刀片模板:
<!doctype html>
<head>
<meta charset="utf-8">
<title>Laravel</title>
<!-- CSRF Token -->
<meta name="csrf-token" content="{{ csrf_token() }}">
</head>
<body>
<div class="flex-center position-ref full-height">
<div id="app">
<ilist></ilist>
</div>
</div>
<script src="/js/app.js"></script>
</body>
</html>
我的 assets/js/app.js 文件:
require('./bootstrap');
window.Vue = require('vue');
let axios = require('axios');
Vue.component('ilist', require('./components/Ilist.vue'));
const app = new Vue({
el: '#app'
});
我更改了 assets/js/bootstrap.js
// let token = document.head.querySelector('meta[name="csrf-token"]');
//
// if (token) {
// window.axios.defaults.headers.common['X-CSRF-TOKEN'] = token.content;
// } else {
// console.error('CSRF token not found: https://laravel.com/docs/csrf#csrf-x-csrf-token');
// }
window.axios.defaults.headers.post['Content-Type'] = 'application/x-www-form-urlencoded';
我想在 ul,li 列表中显示 https://api.github.com/repos/waffleio/waffle.io/issues 数据。我应该怎么做? 然后我只需安装新的 Larave,然后运行这些命令:npm install、npm run watch。
【问题讨论】:
-
将
this.info = response.data.bpi;更新为this.info = response; -
你得到一个数组作为 response.data。这就是 response.data.bpi 未定义的原因
-
好的。我更改了 Ilist.vue:mounted () { axios .get('api.github.com/repos/waffleio/waffle.io/issues') .then((response) => { console.log(response); 这个。 info = response; }) } 但我仍然得到空白屏幕
标签: laravel vue.js vuejs2 axis