传值 keywords
<template> <van-list v-model="loading" :finished="finished" finished-text="没有更多了" @load="onLoad" > <van-cell v-for="(item, index) in list" :key="index" :title="item.title" /> </van-list> </template> <script> import { getSuggestApi } from "@/api/Search"; export default { data() { return { list: [], loading: false, finished: false, page: 1, per_page: 10, }; }, created() { console.log(this.keywords); }, props: { keywords: { type: String, required: true, }, }, methods: { async onl oad() { // 1.发送请求数据 const { data } = await getSuggestApi({ page: this.page, per_page: this.per_page, q: this.keywords, }); // console.log(data); // 2. 将数据追加到列表中 this.list.push(...data.data.results); console.log(this.list); // 3. 关闭loading this.loading = false; // 4. 判断是否结束 if (this.list.length < data.data.total_count) { // 还有数据没有加载完,继续请求数据 this.page++; } else { // 没有数据了,结束onLoad函数 this.finished = true; } }, }, }; </script> <style> </style>
标签:loading,封装,list,搜索,上拉,keywords,false,data,page From: https://www.cnblogs.com/zhulongxu/p/16811138.html