赞
踩
步骤:
views
下面创建一个 home
文件夹,再在里面建一个index.vue
文件const routes = [ { path: '/useVant', component: UseVant }, { path: '/', component: Login }, { path: '/home', component: Home, children: [ { // path: 'index', // 访问的路径为: /home/index path: '/index', // 访问的路径为: /index component: Index }, { path: '/my', component: My }, { path: '/question', component: Question }, { path: '/video', component: Video } ] } ]
tabBar
完成路由跳转<template>
<div>
<router-view></router-view>
<van-tabbar route>
<van-tabbar-item to="/index" icon="home-o">主页</van-tabbar-item>
<van-tabbar-item to="/question" icon="search">问答</van-tabbar-item>
<van-tabbar-item to="/video" icon="friends-o">视频</van-tabbar-item>
<van-tabbar-item to='/my' icon="user-o">我的</van-tabbar-item>
</van-tabbar>
</div>
</template>
步骤:
views
下面创建 index
& my
index
& my
设置为 home
的子路由home
中添加 router-view
布局情况:
使用vant中的 van-nav-bar
使用 vant 中的 tab 组件
说明如果要文章区域可以上拉加载更多,需要使用到 vant 中的一个组件:list 组件
属性:
v-model:是否处于正在上拉加载更多的操作
finished:list 数据源中的数据是否完全加载完成
事件:
load:当 List 组件在上拉加载更多时,会执行的事件
步骤:
list
组件将文章内容包裹起来步骤:
在频道区域的右侧添加一个按钮
步骤:
问题:由于黑马头条是一个新闻类的网站,需要向上滑动时加载更多的信息,需要完成上拉加载更多
方案:可以使用 vant 中的组件来完成: list
案例:
注意点:
执行时机:
1.0 当 list 组件被加载时会执行一次
2.0 当页面的滚动条触底时会再次执行 onload
3.0 要进行内容拼接时,不用 push ,用[...this.list, ...arr]
要实现下拉刷新,需要单独添加一个组件:PullRefresh
PullRefresh
属性:
refresh
事件事件:
refresh
:
当下拉之后:
主页views下的index文件夹下的index.vue组件代码:
<template> <div class="index"> <!-- 头部标题--> <van-nav-bar title="主页" fixed /> <!-- 频道区域 --> <van-tabs> <van-tab v-for="index in 8" :title="'标签 ' + index" :key="index"> <!-- 下拉刷新 --> <van-pull-refresh v-model="isLoading" @refresh="onRefresh"> <!-- 上拉显示下面数据 --> <van-list v-model="loading" :finished="finished" finished-text="没有更多了" @load="onLoad"> <van-cell v-for="item in list" :key="item" :title="item" /> </van-list> </van-pull-refresh> </van-tab> </van-tabs> <!-- 操作按钮 --> <div class="process"> <van-icon name="bars" /> </div> </div> </template> <script> export default { data () { return { // list组件的 加载状态 loading: false, // 判断list组件中的数据是否全部加载完毕 finished: false, // ceil的数据源 list: [], // 下拉刷新组件的刷新状态 isLoading: false } }, methods: { // 当list组件滚动到底部是会触发这个事件 onLoad () { console.log('到底') // 会在list触底时加载:添加15条数据 var arr = [1, 2, 3, 4, 5, 6, 7, 8, 9, 10, 11, 12, 13, 14, 15, 16, 17, 18, 19, 20] // 将这20条数据加载到list中 this.list = [...this.list, ...arr] // 还有数据 不用加载 this.loading = false // 判断长度,如果达到100就停止显示没有数据 if (this.list.length >= 100) { this.finished = true // 停止加载 } }, // 下拉刷新触发的方法 onRefresh () { setTimeout(() => { // 刷新完之后不用加载就将v-model设置为false this.isLoading = false // 把list清空 this.list = [] this.finished = false // 继续加载 this.onLoad() }, 2000) } } } </script>
Copyright © 2003-2013 www.wpsshop.cn 版权所有,并保留所有权利。