我在使用vue-apollo从这个端点接收电影数据时遇到了很多问题。
端点: http: //movie-database-graphql.herokuapp.com/graphiql
这就是我配置它的方式(Vuetify 用于造型顺便说一句):
main.js
import Vue from 'vue'
import App from './App.vue'
// Plugins
import './plugins/vuetify'
import VueApollo from 'vue-apollo'
import ApolloClient from 'apollo-boost'
const apolloClient = new ApolloClient({
uri: 'http://movie-database-graphql.herokuapp.com/graphql'
});
const apolloProvider = new VueApollo({
defaultClient: apolloClient,
})
Vue.use(VueApollo);
Vue.config.productionTip = false
new Vue({
apolloProvider,
render: h => h(App)
}).$mount('#app')
我相信问题出在我如何通过 Apollo 调用数据库但还不确定。我尝试了很多方法,遵循文档并且总是失败。
MovieList.vue(带有查询的组件)
<template>
<v-container fluid grid-list-md>
<v-layout row wrap>
<h4 v-if="$apollo.loading">Loading...</h4>
<v-flex v-for="movie in movies" :key="movie.id" xs12 sm6>
<v-card height="150px">
<v-layout row>
<v-avatar size="125" tile>
<v-img :src="movie.poster_path" contain></v-img>
</v-avatar>
<v-flex xs12 sm6>
<v-card-title primary-title>
<h3>{{ movie.title }}</h3>
</v-card-title>
</v-flex>
</v-layout>
</v-card>
</v-flex>
</v-layout>
</v-container>
</template>
<script>
import gql from "graphql-tag"
export default {
name: "MovieList",
data: () => { return { movies: [] } },
apollo: {
movies: gql`
query AllMoviesQuery {
movies(query: "Start Wars") {
id
title
poster_path
}
}`
}
};
</script>
你明白我错过了什么吗?我没有收到任何电影数据(没有显示错误...)。电影数组总是空的