问题描述
在方法中重新获取 GraphQL 查询后,我在运行代码时遇到问题。如下面的代码所示,当我在挂载中重新获取查询时,在 .then 之后我传递了一些数据并且它运行正常。不幸的是,当我在 sortDate() 方法中以同样的方式执行 .then 之后没有代码运行,即使我尝试使用简单的 console.log。
预先感谢您提供任何提示,为什么会这样。
<script>
import pagination from '@/mixins/pagination'
import { VIDEOS_SELLER } from '@/graphQL/query/videos'
export default {
mixins: [pagination],data() {
return {
isLoading: true,typeList: 'videos',list: [],videos: {
list: [],totalCount: null
},argumentLast: true,sortingColumn: 'ADDED',sortingDirection: 'ASC'
}
},apollo: {
videos: {
query: VIDEOS_SELLER,variables() {
return {
last: this.paginationPerPage,before: '',seller: this.getSeller !== null ? this.getSeller.id : '',direction: this.sortingDirection,field: this.sortingColumn
}
},update: (data) => {
const videos = {
totalCount: data.videos.totalCount,list: []
}
data.videos.edges.forEach((elem) => {
const item = { 'cursor': elem.cursor,...elem.node }
videos.list.push(item)
})
console.log(videos)
videos.list.reverse()
return videos
}
}
},computed: {
moreLoadItem() {
return this.videos.list < this.videos.totalCount
},count() {
return this.videos.totalCount
}
},mounted() {
this.$apollo.queries.videos.refetch().then(() => {
this.list = this.videos.list
this.isLoading = false
})
},methods: {
details(id) {
return this.$router.push(`/videos/${id}`).catch((error) => {})
},sortDate() {
if (this.sortingColumn !== 'ADDED') {
this.sortingColumn = 'ADDED'
this.sortingDirection = 'ASC'
} else if (this.sortingDirection === 'ASC') {
this.sortingDirection = 'DESC'
this.$apollo.queries.videos.refetch().then(() => {
this.list = this.videos.list
this.isLoading = false
})
} else if (this.sortingDirection === 'DESC') {
this.sortingDirection = 'ASC'
this.$apollo.queries.videos.refetch().then(() => {
this.list = this.videos.list
this.isLoading = false
})
}
}
}
}
</script>
解决方法
暂无找到可以解决该程序问题的有效方法,小编努力寻找整理中!
如果你已经找到好的解决方法,欢迎将解决方案带上本链接一起发送给小编。
小编邮箱:dio#foxmail.com (将#修改为@)