網(wǎng)站首頁 編程語言 正文
1.tab切換 時每次想后臺返回一個唯一的name參數(shù),就可以實現(xiàn)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("數(shù)據(jù)",this.recommandList);
}
},
// tab.name唯一標(biāo)識
handleClick(tab, event) {
// console.log(tab, event);
this.getRecomList(tab.name);
}
},
};
</script>
2.如果后臺返回的是一個數(shù)組對象嵌套子數(shù)組數(shù)據(jù)的結(jié)構(gòu),可以雙層for循環(huán)出來直接每一項展示
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: '編碼規(guī)范',
id: 22,
createDate: '2022-04-20T22:18:07'
},
{
children: [
[Object], [Object],
[Object], [Object],
[Object], [Object],
[Object], [Object],
[Object]
],
name: '構(gòu)建工具',
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: '技術(shù)社區(qū)',
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: '網(wǎng)絡(luò)資訊',
id: 2,
createDate: '2021-11-06T22:27:51'
},
{
children: [ [Object], [Object], [Object], [Object], [Object], [Object] ],
name: '開發(fā)工具',
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
- 上一篇:沒有了
- 下一篇:沒有了
相關(guān)推薦
- 2022-03-14 事務(wù)隔離級別 在spring實戰(zhàn)
- 2023-03-17 使用c語言輕松實現(xiàn)動態(tài)內(nèi)存管_C 語言
- 2022-04-30 Python代碼顯得Pythonic(區(qū)別于其他語言的寫法)_python
- 2022-03-29 C#算法之兩數(shù)之和_C#教程
- 2022-03-17 golang?數(shù)組隨機(jī)排序的實現(xiàn)_Golang
- 2022-03-16 C語言庫函數(shù)中qsort()的用法_C 語言
- 2023-02-01 Bat腳本-Call,Start,直接調(diào)用,goto?四種方式調(diào)用批處理_DOS/BAT
- 2022-04-20 C++的數(shù)據(jù)類型你真的了解嗎_C 語言
- 欄目分類
-
- 最近更新
-
- window11 系統(tǒng)安裝 yarn
- 超詳細(xì)win安裝深度學(xué)習(xí)環(huán)境2025年最新版(
- Linux 中運(yùn)行的top命令 怎么退出?
- MySQL 中decimal 的用法? 存儲小
- get 、set 、toString 方法的使
- @Resource和 @Autowired注解
- Java基礎(chǔ)操作-- 運(yùn)算符,流程控制 Flo
- 1. Int 和Integer 的區(qū)別,Jav
- spring @retryable不生效的一種
- Spring Security之認(rèn)證信息的處理
- Spring Security之認(rèn)證過濾器
- Spring Security概述快速入門
- Spring Security之配置體系
- 【SpringBoot】SpringCache
- Spring Security之基于方法配置權(quán)
- redisson分布式鎖中waittime的設(shè)
- maven:解決release錯誤:Artif
- restTemplate使用總結(jié)
- Spring Security之安全異常處理
- MybatisPlus優(yōu)雅實現(xiàn)加密?
- Spring ioc容器與Bean的生命周期。
- 【探索SpringCloud】服務(wù)發(fā)現(xiàn)-Nac
- Spring Security之基于HttpR
- Redis 底層數(shù)據(jù)結(jié)構(gòu)-簡單動態(tài)字符串(SD
- arthas操作spring被代理目標(biāo)對象命令
- Spring中的單例模式應(yīng)用詳解
- 聊聊消息隊列,發(fā)送消息的4種方式
- bootspring第三方資源配置管理
- GIT同步修改后的遠(yuǎn)程分支