传给list-card。//这里的@change可是系统的哈。......_uniapp 选项卡">
赞
踩
目录
别看“二、”这么多哈 都是虚的 目的就是 把云函数获取的数组 传给list-card list引用后 传给list-item(看看那个云数组有几条?好显示) ->list-card
3.field content:false 不要content
- <swiper style="height: 100%;">
- <swiper-item class="home-swiper">
- <view>我是小狗</view>
- <view>我是小狗</view>
- <view>我是小狗</view>
- <list-card></list-card>
- </swiper-item>
- </swiper>
效果:可以左右滑动
//这里的@change可是系统的哈
<swiper @change="change">
@自己定义的名=“用啥处理”
- <list :tab="tabList" @change="change"></list>
- <!-- //index界面里接受 发来的current(当前选项卡的下标数) -->
这里的@change是自己定义的哈 可不是系统的 是因为咱 在定义子组件发送时间名的时候 设置的
this.$emit('change', current)
- change(e)
- {
- console.log('嘘嘘嘘',e);
- const {current}=e.detail;//取到 current这个数据
- this.$emit('change', current)
- }
<tab :list="tabList" :tabIndex="tabIndex" @tab="tab"></tab>
首先props接收index 传来的参数 然后在watch里监听它
- watch:{
- tabIndex(a,b){//监听哪个就写哪个 把props里面的属性写成函数就行啦
- console.log('汪汪汪',a,b)//a是改变后的数据 b是改变前的数据
- this.activeIndex=a;
- }
activeindex 你自己定义的 你一变 那啥也变
这样就是实现了 滑动 ——>上面的tab跟着变
首先 获取tab点击时 的下标传递给 list (list里面写了swiper swiper里有个current :current="activeIndex" 会自动跳到咱想要的界面)
发送:
- this.$emit('tab', {
- data: item,
- index: index
- })
接收:
@tab="tab"
index定义一个activeIndex
<list :tab="tabList" @change="change" :activeIndex="activeIndex"></list>
list用 props接收一个activeIndex
- activeIndex:{
- type:Number,
- default:0
- }
接收后直接
<swiper @change="change" :current="activeIndex">
完成了双向滑动啦
别看“二、”这么多哈 都是虚的 目的就是 把云函数获取的数组 传给list-card list引用后 传给list-item(看看那个云数组有几条?好显示) ->list-card
- 'use strict';
- const db=uniCloud.database()//1.创建引用
- exports.main = async (event, context) => {
- //event为客户端上传的参数
-
- const list =await db.collection('article') //2.创建
- .field({//指定返回的字段
- content:false,//TRUE 表示只返回content
- }).get()
- //返回数据给客户端
-
- return {
- code: 200,
- msg: '数据请求成功',
- data: list.data
- }
- };
![](https://csdnimg.cn/release/blogv2/dist/pc/img/newCodeMoreWhite.png)
(原理不在此赘述)
- export const get_list = (data) => {
- return $http({
- url: 'get_list',
- data
- })
- }
- getList()
- {
- this.$api.get_list().then(res=>{
- console.log('小狗狗',res);//验证对不对 res
- this.list=res.data
- const {data}=res;//这俩一个效果
- console.log('小白白',data);
- })
- //console.log('小狗狗');
- created(){
- this.getList()
- },
list中发送: :list="list"
- props: {//获取 list引用api中数据库返回的数组
- list: {
- type: Array,
- default () {
- return []
- }
- },
<list-item :list="list"></list-item>
onLoad 在页面 ,created 组件
1.用咱拿到的数组 v-for="item in list" (看这里的item 它是list数组中的一个哈 鸟小 五脏俱全)
<list-card mode="base" :item="item" v-for="item in list" :key="item._id"></list-card>
但这样只是拿到了几个 并没有真正把数据整到界面上 因为咱那个界面是 list-card里面写的界面内容--->传给list-card
接收:props: {
item: {
type: Object,
default () {
return {}
}
}
},
先复制一个 一共仨 一个道理 这里只copy了一个哈
- <view v-if="item.mode === 'base'" class="listcard">
- <view class="listcard-image">
- <image :src="item.cover[0]" mode="aspectFill"></image>
- </view>
- <view class="listcard-content">
- <view class="listcard-content__title">
- <text>{{item.title}}</text>
-
- </view>
- <view class="listcard-content__des">
- <view class="listcard-content__des-label">
- <view class="listcard-content__des-label-item">{{item.classify}}</view>
- </view>
- <view class="listcard-content__des-browse">{{item.browse_count}}浏览</view>
- </view>
- </view>
- </view>
![](https://csdnimg.cn/release/blogv2/dist/pc/img/newCodeMoreWhite.png)
这样就可以啦!!!
很明显哈 这里面需要根据标签名传参数 所以云函数得能接受参数
- const {
-
- name,
-
- } = event//等同 var name=event.name
- const list =await db.collection('article') //2.创建
- .aggregate()//获取聚合操作实例
- .match({
- classify:'前端开发'
- })//筛选出classify是前端开发的
- .project({
- content:0
- })//类似.field
- .end()
返回的结果全是前端开发的
所谓懒加载就是,存到数组里面 加载过的不用每次都加载
- watch: {
- tab(newVal) {
- if (newVal.length === 0) return
- this.listCatchData = {}
- this.getList(this.activeIndex)
- }
- },
- methods: {
- getList(current) {
- this.$api.get_list({
- name: this.tab[current].name,
- }).then(res => {
- console.log(res);
- const {
- data
- } = res
- this.$set(this.listCatchData, current, data)
- })
- },
- change(e) {
- console.log('嘘嘘嘘', e);
- const {
- current
- } = e.detail; //取到 current这个数据
- this.$emit('change', current)
- console.log("呆呆:", this.tab[current].name)
- console.log("笨笨:", current)
- this.getList(current)
- },
![](https://csdnimg.cn/release/blogv2/dist/pc/img/newCodeMoreWhite.png)
ok
Copyright © 2003-2013 www.wpsshop.cn 版权所有,并保留所有权利。