最新国产好看的视频,伊人天堂AV在线,国产Aaaaaa视频,蜜臀视频在线观看一区,人妻av色图,密臀久久久精品影片,青青视频免费观看毛片,久草在线观看视,国产三级精品色情在线

vue實現(xiàn)文章評論和回復(fù)列表

 更新時間:2022年04月14日 15:31:52   作者:nao兒  
這篇文章主要為大家詳細(xì)介紹了vue實現(xiàn)文章評論和回復(fù)列表,文中示例代碼介紹的非常詳細(xì),具有一定的參考價值,感興趣的小伙伴們可以參考一下

本文實例為大家分享了vue實現(xiàn)文章評論和回復(fù)列表的具體代碼,供大家參考,具體內(nèi)容如下

效果預(yù)覽:

父組件:

<template>
? <div class="comment-reply">
? ? <div
? ? ? v-for="(item, index) in articleLists"
? ? ? :key="index"
? ? ? class="article-list"
? ? >
? ? ? <div class="article-desc">{{ item.articleDesc }}</div>
? ? ? <div v-if="item.children.length > 0">
? ? ? ? <div class="reply-list" v-if="item.children.length > 0">
? ? ? ? ? <my-cycle-list
? ? ? ? ? ? v-for="(comment, index) in item.children"
? ? ? ? ? ? :self="comment"
? ? ? ? ? ? :parent="comment"
? ? ? ? ? ? :key="index"
? ? ? ? ? ></my-cycle-list>
? ? ? ? </div>
? ? ? </div>
? ? </div>
? </div>
</template>
<script>
import myCycleList from '@/components/my-cycle-list'
export default {
? components: { myCycleList },
? data() {
? ? return {
? ? ? // 文章列表
? ? ? articleLists: [
? ? ? ? { articleId: 'article-1', articleDesc: '圍城' },
? ? ? ? { articleId: 'article-2', articleDesc: '駱駝祥子' },
? ? ? ? { articleId: 'article-3', articleDesc: '邊城' },
? ? ? ? { articleId: 'article-4', articleDesc: '朝花夕拾' }
? ? ? ],
? ? ? // 評論列表
? ? ? commentsList: [
? ? ? ? {
? ? ? ? ? userId: 'user-1',
? ? ? ? ? userName: '趙一',
? ? ? ? ? articleId: 'article-1', // 關(guān)聯(lián)的文章id
? ? ? ? ? commentId: 'comment-1', // 評論id
? ? ? ? ? replyId: null, // 回復(fù)哪條評論的id
? ? ? ? ? desc: '作者是誰',
? ? ? ? ? time: '2021-04-05 15:30:25'
? ? ? ? },
? ? ? ? {
? ? ? ? ? userId: 'user-2',
? ? ? ? ? userName: '錢二',
? ? ? ? ? articleId: 'article-1',
? ? ? ? ? commentId: 'comment-2',
? ? ? ? ? replyId: null,
? ? ? ? ? desc: '對呀,作者也不寫',
? ? ? ? ? time: '2021-04-05 15:30:25'
? ? ? ? },
? ? ? ? {
? ? ? ? ? userId: 'user-3',
? ? ? ? ? userName: '孫三',
? ? ? ? ? articleId: 'article-1',
? ? ? ? ? commentId: 'comment-3',
? ? ? ? ? replyId: null,
? ? ? ? ? desc: '樓上倆初中沒畢業(yè)吧',
? ? ? ? ? time: '2021-04-05 15:30:25'
? ? ? ? },
? ? ? ? {
? ? ? ? ? userId: 'user-4',
? ? ? ? ? userName: '李四',
? ? ? ? ? articleId: 'article-1',
? ? ? ? ? commentId: 'comment-4',
? ? ? ? ? replyId: 'comment-1',
? ? ? ? ? desc: '作者是錢鐘書',
? ? ? ? ? time: '2021-04-05 15:30:25'
? ? ? ? },
? ? ? ? {
? ? ? ? ? userId: 'user-9',
? ? ? ? ? userName: '牛九',
? ? ? ? ? articleId: 'article-1',
? ? ? ? ? commentId: 'comment-10',
? ? ? ? ? replyId: 'comment-1',
? ? ? ? ? desc: '錢鐘書',
? ? ? ? ? time: '2021-04-05 15:30:25'
? ? ? ? },
? ? ? ? {
? ? ? ? ? userId: 'user-5',
? ? ? ? ? userName: '王五',
? ? ? ? ? articleId: 'article-2',
? ? ? ? ? commentId: 'comment-5',
? ? ? ? ? replyId: null,
? ? ? ? ? desc: '哈哈哈',
? ? ? ? ? time: '2021-04-05 15:30:25'
? ? ? ? },
? ? ? ? {
? ? ? ? ? userId: 'user-6',
? ? ? ? ? userName: '張六',
? ? ? ? ? articleId: 'article-1',
? ? ? ? ? commentId: 'comment-6',
? ? ? ? ? replyId: 'comment-4',
? ? ? ? ? desc: '不對吧',
? ? ? ? ? time: '2021-04-05 15:30:25'
? ? ? ? },
? ? ? ? {
? ? ? ? ? userId: 'user-7',
? ? ? ? ? userName: '顧七',
? ? ? ? ? articleId: 'article-1',
? ? ? ? ? commentId: 'comment-7',
? ? ? ? ? replyId: 'comment-6',
? ? ? ? ? desc: '對的,就是錢鐘書',
? ? ? ? ? time: '2021-04-05 15:30:25'
? ? ? ? },
? ? ? ? {
? ? ? ? ? userId: 'user-8',
? ? ? ? ? userName: '朱八',
? ? ? ? ? articleId: 'article-3',
? ? ? ? ? commentId: 'comment-8',
? ? ? ? ? replyId: null,
? ? ? ? ? desc: '這本書真不錯',
? ? ? ? ? time: '2021-04-05 15:30:25'
? ? ? ? },
? ? ? ? {
? ? ? ? ? userId: 'user-9',
? ? ? ? ? userName: '紀(jì)九',
? ? ? ? ? articleId: 'article-4',
? ? ? ? ? commentId: 'comment-9',
? ? ? ? ? replyId: null,
? ? ? ? ? desc: '真的好看',
? ? ? ? ? time: '2021-04-05 15:30:25'
? ? ? ? }
? ? ? ]
? ? }
? },
? created() {
? ? this.initCommentLists()
? ? this.initArticleLists()
? },
? methods: {
? ? // 格式化評論數(shù)據(jù)
? ? initCommentLists() {
? ? ? this.commentsList.forEach(i => {
? ? ? ? this.$set(i, 'children', [])
? ? ? ? // 將回復(fù)該評論的列表放入children中
? ? ? ? let filterList = this.commentsList.filter(
? ? ? ? ? j => j.replyId === i.commentId
? ? ? ? )
? ? ? ? if (filterList.length > 0) {
? ? ? ? ? i.children = filterList
? ? ? ? }
? ? ? })
? ? ? // 過濾出最高級
? ? ? this.commentsList = this.commentsList.filter(i => i.replyId === null)
? ? },
? ? // 格式化文章數(shù)據(jù)
? ? initArticleLists() {
? ? ? this.articleLists.forEach(i => {
? ? ? ? this.$set(i, 'children', [])
? ? ? ? let filterList = this.commentsList.filter(
? ? ? ? ? j => j.articleId === i.articleId
? ? ? ? )
? ? ? ? if (filterList.length > 0) {
? ? ? ? ? i.children = filterList
? ? ? ? }
? ? ? })
? ? }
? }
}
</script>
<style scoped lang="scss">
.comment-reply {
? .article-list {
? ? margin: 15px;
? ? .article-desc {
? ? ? color: coral;
? ? ? font-size: 26px;
? ? ? font-weight: bold;
? ? }
? }
? .comment-list {
? ? margin: 10px;
? ? .comment {
? ? ? .comment-username {
? ? ? ? color: #999;
? ? ? ? cursor: pointer;
? ? ? }
? ? }
? }
}
</style>

my-cycle-list組件:

<template>
? <div class="my-cycle-list">
? ? <div class="lists">
? ? ? <!-- 回復(fù) -->
? ? ? <div v-if="self.replyId">
? ? ? ? <span class="self-username"> {{ self.userName }} 回復(fù) </span>
? ? ? ? <span class="parent-username" @click="parentClick"
? ? ? ? ? >{{ parent.userName }}:</span
? ? ? ? >
? ? ? ? {{ self.desc }}
? ? ? ? <span class="time">{{ self.time }}</span>
? ? ? </div>
? ? ? <!-- 評論 -->
? ? ? <div v-else>
? ? ? ? <span class="self-username" @click="commentUserNameClick">
? ? ? ? ? {{ self.userName }}:
? ? ? ? </span>
? ? ? ? {{ self.desc }}
? ? ? ? <span class="time">{{ self.time }}</span>
? ? ? </div>
? ? ? <!-- 遞歸組件 -->
? ? ? <div v-if="self.children.length < flagNum || showAll">
? ? ? ? <my-cycle-list
? ? ? ? ? v-for="(child, index) in self.children"
? ? ? ? ? :self="child"
? ? ? ? ? :parent="self"
? ? ? ? ? :key="index"
? ? ? ? ></my-cycle-list>
? ? ? </div>
? ? ? <!-- 查看全部 -->
? ? ? <div
? ? ? ? v-if="self.children.length >= flagNum"
? ? ? ? class="view-all"
? ? ? ? @click="viewAll"
? ? ? >
? ? ? {{ !showAll ? `查看全部 ${self.children.length} 條回復(fù)` : `收起 ${self.children.length} 條回復(fù)`}}
? ? ? ? ?
? ? ? </div>
? ? </div>
? </div>
</template>
<script>
import myCycleList from '@/components/my-cycle-list'
export default {
? props: ['self', 'parent'],
? components: { myCycleList },
? name: 'my-cycle-list',
? data() {
? ? return {
? ? ? flagNum: 2, // 超過多少條折疊
? ? ? showAll: false
? ? }
? },
? created() {},
? methods: {
? ? // 點擊被回復(fù)的昵稱事件
? ? parentClick() {
? ? ? console.log(this.parent)
? ? },
? ? // 評論人點擊事件
? ? commentUserNameClick() {
? ? ? console.log(this.self)
? ? },
? ? // 查看/收起回復(fù)
? ? viewAll() {
? ? ? this.showAll = !this.showAll
? ? }
? }
}
</script>
<style scoped lang="scss">
.my-cycle-list {
? .lists {
? ? margin: 10px;
? ? .self-username {
? ? ? cursor: pointer;
? ? ? color: #999;
? ? }
? ? .parent-username {
? ? ? color: burlywood;
? ? ? cursor: pointer;
? ? }
? ? .time {
? ? ? margin: 0 10px;
? ? ? color: #666;
? ? ? font-size: 12px;
? ? }
? ? .view-all {
? ? ? margin: 10px 0;
? ? ? color: darkcyan;
? ? ? cursor: pointer;
? ? }
? }
}
</style>

以上就是本文的全部內(nèi)容,希望對大家的學(xué)習(xí)有所幫助,也希望大家多多支持腳本之家。

相關(guān)文章

  • Vue中watch監(jiān)聽屬性新舊值相同的問題解決方案

    Vue中watch監(jiān)聽屬性新舊值相同的問題解決方案

    這篇文章主要給大家分享了Vue中watch監(jiān)聽屬性新舊值相同問題解決方案,如果有遇到相同問題的朋友,可以參考閱讀本文
    2023-08-08
  • vue實現(xiàn)拖拽的簡單案例 不超出可視區(qū)域

    vue實現(xiàn)拖拽的簡單案例 不超出可視區(qū)域

    這篇文章主要為大家詳細(xì)介紹了vue實現(xiàn)拖拽的簡單案例,不超出可視區(qū)域,具有一定的參考價值,感興趣的小伙伴們可以參考一下
    2019-07-07
  • 解決vue中修改了數(shù)據(jù)但視圖無法更新的情況

    解決vue中修改了數(shù)據(jù)但視圖無法更新的情況

    今天小編就為大家分享一篇解決vue中修改了數(shù)據(jù)但視圖無法更新的情況,具有很好的參考價值,希望對大家有所幫助。一起跟隨小編過來看看吧
    2018-08-08
  • VUE引入騰訊地圖并實現(xiàn)軌跡動畫的詳細(xì)步驟

    VUE引入騰訊地圖并實現(xiàn)軌跡動畫的詳細(xì)步驟

    這篇文章主要介紹了VUE引入騰訊地圖并實現(xiàn)軌跡動畫,引入步驟大概是在 html 中通過引入 script 標(biāo)簽加載API服務(wù),結(jié)合實例代碼給大家介紹的非常詳細(xì),需要的朋友可以參考下
    2022-09-09
  • 如何使用Vue3+elementPlus的Tree組件實現(xiàn)一個拖拽文件夾管理

    如何使用Vue3+elementPlus的Tree組件實現(xiàn)一個拖拽文件夾管理

    最近在做一個文件夾管理的功能,要實現(xiàn)一個樹狀的拖拽文件夾面板,里面包含兩種元素,文件夾以及文件,這篇文章主要介紹了使用Vue3+elementPlus的Tree組件實現(xiàn)一個拖拽文件夾管理?,需要的朋友可以參考下
    2023-09-09
  • Vue動態(tài)綁定class、style、background的方式

    Vue動態(tài)綁定class、style、background的方式

    文章主要介紹了在Vue.js中如何使用動態(tài)綁定class、style和background來實現(xiàn)動態(tài)樣式和背景圖的設(shè)置,通過v-bind指令,可以靈活地根據(jù)數(shù)據(jù)變化來動態(tài)更新元素的樣式和背景
    2025-01-01
  • 淺談vue項目如何打包扔向服務(wù)器

    淺談vue項目如何打包扔向服務(wù)器

    本篇文章主要介紹了淺談vue項目如何打包扔向服務(wù)器,小編覺得挺不錯的,現(xiàn)在分享給大家,也給大家做個參考。一起跟隨小編過來看看吧
    2018-05-05
  • Vue3純前端實現(xiàn)Vue路由權(quán)限的方法詳解

    Vue3純前端實現(xiàn)Vue路由權(quán)限的方法詳解

    這篇文章主要給大家介紹了關(guān)于Vue3純前端實現(xiàn)Vue路由權(quán)限的相關(guān)資料,文中通過實例代碼介紹的非常詳細(xì),對大家學(xué)習(xí)或者使用Vue3具有一定的參考學(xué)習(xí)價值,需要的朋友可以參考下
    2022-05-05
  • Vue中封裝input組件的實例詳解

    Vue中封裝input組件的實例詳解

    這篇文章主要介紹了Vue中封裝input組件的實例詳解的相關(guān)資料,希望通過本文能幫助到大家,需要的朋友可以參考下
    2017-10-10
  • Vue3實現(xiàn)組件二次封裝的小技巧分享

    Vue3實現(xiàn)組件二次封裝的小技巧分享

    組件的二次封裝:保留組件已有的功能,需要重寫組件方法,當(dāng)組件已有大量功能時候,則需要重寫很多重復(fù)代碼,且組件功能進(jìn)行修改的時候,封裝的組件也需要對應(yīng)修改,從而造成許多開發(fā)和維護(hù)成本,本文給大家分享了Vue3實現(xiàn)組件二次封裝的小技巧,需要的朋友可以參考下
    2024-09-09

最新評論

友谊县| 清远市| 巴塘县| 高平市| 翁源县| 眉山市| 无棣县| 上杭县| 东海县| 北票市| 舟山市| 岳阳县| 德格县| 新郑市| 利辛县| 扎赉特旗| 盐城市| 青铜峡市| 瓦房店市| 什邡市| 河源市| 建湖县| 泽库县| 大渡口区| 通州市| 开阳县| 德惠市| 陆良县| 新河县| 青神县| 宁夏| 土默特左旗| 望江县| 保亭| 烟台市| 博客| 乐平市| 施秉县| 当涂县| 菏泽市| 左贡县|