问题
I am frontend developer so for the first time I got my hands on vue and graphql, I don’t know how exactly to deal with this error:
Missing getMovies attribute on result {movies: Array(20)}
Here is my code, and I can see the data is fetched successfully in the response on dev tools in chrome:
{"data":{"movies":[{"__typename":"Movie","id":11,"overview":
Here is the code:
<template>
<div class="hello">
<ul>
<li v-for="movie in movies" :key="movie.id">{{movie.title}}</li>
</ul>
</div>
</template>
<script>
import gql from 'graphql-tag'
export default {
name: 'HelloWorld',
data(){
return {
movies: []
}
},
apollo: {
getMovies: {
query: gql`
query StarWars {
movies(query: "Star Wars") {
title
overview
poster_path
id
}
}
`,
result({data}){
this.movies = data.movies
}
}
},
props: {
msg: String
}
}
</script>
回答1:
Per this issue, your apollo
property should have a matching data
property, but in this case they are mismatched (one is named movies
and getMovies
). Change one or the other:
export default {
name: 'HelloWorld',
data(){
return {
movies: []
}
},
apollo: {
movies: {
query: gql`
query StarWars {
movies(query: "Star Wars") {
title
overview
poster_path
id
}
}
`
}
},
props: {
msg: String
}
}
Setting the data
yourself inside result
isn't necessary.
来源:https://stackoverflow.com/questions/56723183/missing-movies-attribute-on-result-vue-graphql