網站首頁 編程語言 正文
1.tab切換 時每次想后臺返回一個唯一的name參數,就可以實現tab切換
<div class="cate">推薦閱讀</div>
<el-tabs v-model="activeName" @tab-click="handleClick">
<el-tab-pane label="最近30天" name="30"></el-tab-pane>
<el-tab-pane label="本年度" name="365"></el-tab-pane>
<el-tab-pane label="總排行" name="all"></el-tab-pane>
</el-tabs>
<ul>
<li v-for="(item, index) in recommandList" :key="index">
<div class="title">
<a :href="'/post/' + (item.uid || item.id)" target="_blank">
<span class="list-index">{{ index + 1 }}</span
>{{ item.title }}
</a>
</div>
<div class="excerpt">
<span class="views el-icon-date"> {{ item.createDate }}</span>
<span class="views el-icon-view"> 閱讀({{ item.views }})</span>
</div>
</li>
</ul>
<script>
import {
getRecomListApi4Brower,
} from "../../pages/post/index";
export default {
props: {},
data() {
return {
recommandList: [],
};
},
computed: {},
methods: {
async getRecomList(type) {
let res = await getRecomListApi4Brower({ type });
if (res) {
this.recommandList = res.data.slice(0,6) //只展示五條
console.log("數據",this.recommandList);
}
},
// tab.name唯一標識
handleClick(tab, event) {
// console.log(tab, event);
this.getRecomList(tab.name);
}
},
};
</script>
2.如果后臺返回的是一個數組對象嵌套子數組數據的結構,可以雙層for循環出來直接每一項展示
client.js?06a0:57 [
{
children: [
[Object], [Object],
[Object], [Object],
[Object], [Object],
[Object], [Object],
[Object], [Object],
[Object], [Object],
[Object], [Object]
],
name: '個人博客',
id: 23,
createDate: '2022-08-01T00:08:30'
},
{
children: [ [Object], [Object], [Object] ],
name: '編碼規范',
id: 22,
createDate: '2022-04-20T22:18:07'
},
{
children: [
[Object], [Object],
[Object], [Object],
[Object], [Object],
[Object], [Object],
[Object]
],
name: '構建工具',
id: 21,
createDate: '2022-04-07T23:01:29'
},
{
children: [
[Object], [Object],
[Object], [Object],
[Object], [Object],
[Object], [Object],
[Object], [Object],
[Object], [Object],
[Object], [Object],
[Object], [Object]
],
name: '框架組件',
id: 20,
createDate: '2022-04-07T22:46:17'
},
{
children: [
[Object], [Object],
[Object], [Object],
[Object], [Object],
[Object]
],
name: '技術社區',
id: 19,
createDate: '2022-02-12T21:13:32'
},
{
children: [ [Object], [Object], [Object], [Object], [Object], [Object] ],
name: '常用工具',
id: 14,
createDate: '2021-11-14T21:33:35'
},
{
children: [
[Object], [Object],
[Object], [Object],
[Object], [Object],
[Object], [Object],
[Object], [Object]
],
name: '資源分享',
id: 3,
createDate: '2021-11-06T22:28:43'
},
{
children: [
[Object], [Object],
[Object], [Object],
[Object], [Object],
[Object], [Object],
[Object]
],
name: '網絡資訊',
id: 2,
createDate: '2021-11-06T22:27:51'
},
{
children: [ [Object], [Object], [Object], [Object], [Object], [Object] ],
name: '開發工具',
id: 1,
createDate: '2021-11-06T20:33:06'
}
]
<el-tabs :tab-position="tabPosition" style="height: 100%">
<el-tab-pane
:label="item.name"
v-for="(item, index) in list"
:key="index"
>
<!--渲染-->
<div class="child-cate">
<div
class="cate-item"
v-for="(it, ix) in item.children"
:key="ix"
>
<el-card shadow="always">
<div class="title">
<a :href="it.url" target="_blank"> {{ it.title }}</a>
</div>
<div class="content">{{ it.content }}</div>
</el-card>
</div>
</div>
</el-tab-pane>
</el-tabs>
<script>
import { getListApi } from "./api";
export default {
data() {
return {
};
},
async asyncData({ query, store, $axios }) {
let res = await getListApi({});
console.log("@@@woaonio",res.data)
return {
list: res.data,
};
},
};
</script>
原文鏈接:https://blog.csdn.net/weixin_50379372/article/details/128033170
- 上一篇:沒有了
- 下一篇:沒有了
相關推薦
- 2022-07-19 Oracle 集群sysbackup用戶登陸隨機報錯ORA-01017
- 2022-07-21 CSS復合型寫法
- 2022-04-21 Docker - Error: Error response from daemon: No com
- 2022-11-17 Python中的優先隊列(priority?queue)和堆(heap)_python
- 2022-10-25 Git中smart?Checkout與force?checkout的區別及說明_相關技巧
- 2022-06-12 Python利用subplots_adjust方法解決圖表與畫布的間距問題_python
- 2023-03-01 Python第三方庫undetected_chromedriver的使用_python
- 2023-12-20 UML類圖中各箭頭表示總結
- 欄目分類
-
- 最近更新
-
- window11 系統安裝 yarn
- 超詳細win安裝深度學習環境2025年最新版(
- Linux 中運行的top命令 怎么退出?
- MySQL 中decimal 的用法? 存儲小
- get 、set 、toString 方法的使
- @Resource和 @Autowired注解
- Java基礎操作-- 運算符,流程控制 Flo
- 1. Int 和Integer 的區別,Jav
- spring @retryable不生效的一種
- Spring Security之認證信息的處理
- Spring Security之認證過濾器
- Spring Security概述快速入門
- Spring Security之配置體系
- 【SpringBoot】SpringCache
- Spring Security之基于方法配置權
- redisson分布式鎖中waittime的設
- maven:解決release錯誤:Artif
- restTemplate使用總結
- Spring Security之安全異常處理
- MybatisPlus優雅實現加密?
- Spring ioc容器與Bean的生命周期。
- 【探索SpringCloud】服務發現-Nac
- Spring Security之基于HttpR
- Redis 底層數據結構-簡單動態字符串(SD
- arthas操作spring被代理目標對象命令
- Spring中的單例模式應用詳解
- 聊聊消息隊列,發送消息的4種方式
- bootspring第三方資源配置管理
- GIT同步修改后的遠程分支