码农知识堂 - 1000bd
  •   Python
  •   PHP
  •   JS/TS
  •   JAVA
  •   C/C++
  •   C#
  •   GO
  •   Kotlin
  •   Swift
  • vue3-布局右侧标签


    在components文件夹下创建一个TagCloud.vue的组件,如下:

    1. <script setup>
    2. import { ref } from "vue";
    3. const tags=ref([]);
    4. const tagArray=[];
    5. const props = defineProps({
    6. posts:Array,
    7. });
    8. props.posts.forEach ((item)=>{
    9. item.tags.forEach((tag)=>
    10. tagArray.push(tag)
    11. )
    12. });
    13. tags.value=tagArray;
    14. script>
    15. <template>
    16. <div>{{tags}}div>
    17. template>
    18. <style scoped>
    19. style>

    这样创建的tags中没有去除重复的标签,咱们进行去重,        代码如下:

    1. <script setup>
    2. import { ref } from "vue";
    3. const tags=ref([]);
    4. const tagSet=new Set();
    5. const props = defineProps({
    6. posts:Array,
    7. });
    8. props.posts.forEach ((item)=>{
    9. item.tags.forEach((tag)=>
    10. tagSet.add(tag)
    11. )
    12. });
    13. tags.value=[...tagSet];
    14. script>
    15. <template>
    16. <div>{{tags}}div>
    17. template>
    18. <style scoped>
    19. style>

    这样就没有重复的元素了。

    可以加点样式,再美化一下页面:

    1. <script setup>
    2. import { ref } from "vue";
    3. const tags=ref([]);
    4. const tagSet=new Set();
    5. const props = defineProps({
    6. posts:Array,
    7. });
    8. console.log(props.posts);
    9. alert(props.posts.length);
    10. props.posts.forEach((item)=>{
    11. item.tags.forEach((tag)=>
    12. tagSet.add(tag)
    13. )
    14. });
    15. tags.value=[...tagSet];
    16. script>
    17. <template>
    18. <div class="tag-cloud">
    19. <h3>标签h3>
    20. <div v-for="tag in tags" :key="tag">
    21. <router-link to="/">#{{tag}}router-link>
    22. div>
    23. div>
    24. template>
    25. <style scoped>
    26. .tag-cloud{
    27. padding:10px;
    28. }
    29. .tag-cloud h3{
    30. border-bottom:1px solid #eee;
    31. padding:16px 8px;
    32. color:#444;
    33. }
    34. .tag-cloud div{
    35. display: inline-block;
    36. padding:10px;
    37. }
    38. .tag-cloud a{
    39. color:#ccc;
    40. text-decoration: none;
    41. }
    42. style>

  • 相关阅读:
    ZYNQ_project:LCD
    概述Linux内核驱动之GPIO子系统API接口
    面向对象【static关键字】
    【Swift 60秒】02 - Strings and Integers
    [c语言]二维数组动态分配内存
    秋招失利,拿到这份“Java 高分指南(25 专题)”,金三银四翻盘有望
    【论文阅读】RadHAR:通过毫米波雷达生成的点云识别人类活动
    Mac 使用 scp 上传或下载文件/文件夹
    【SQL注入】关于GORM的SQL注入问题
    不使用比较和条件判断实现min函数的一种方法
  • 原文地址:https://blog.csdn.net/menghuannvxia/article/details/126284716
  • 最新文章
  • 攻防演习之三天拿下官网站群
    数据安全治理学习——前期安全规划和安全管理体系建设
    企业安全 | 企业内一次钓鱼演练准备过程
    内网渗透测试 | Kerberos协议及其部分攻击手法
    0day的产生 | 不懂代码的"代码审计"
    安装scrcpy-client模块av模块异常,环境问题解决方案
    leetcode hot100【LeetCode 279. 完全平方数】java实现
    OpenWrt下安装Mosquitto
    AnatoMask论文汇总
    【AI日记】24.11.01 LangChain、openai api和github copilot
  • 热门文章
  • 十款代码表白小特效 一个比一个浪漫 赶紧收藏起来吧!!!
    奉劝各位学弟学妹们,该打造你的技术影响力了!
    五年了,我在 CSDN 的两个一百万。
    Java俄罗斯方块,老程序员花了一个周末,连接中学年代!
    面试官都震惊,你这网络基础可以啊!
    你真的会用百度吗?我不信 — 那些不为人知的搜索引擎语法
    心情不好的时候,用 Python 画棵樱花树送给自己吧
    通宵一晚做出来的一款类似CS的第一人称射击游戏Demo!原来做游戏也不是很难,连憨憨学妹都学会了!
    13 万字 C 语言从入门到精通保姆级教程2021 年版
    10行代码集2000张美女图,Python爬虫120例,再上征途
Copyright © 2022 侵权请联系2656653265@qq.com    京ICP备2022015340号-1
正则表达式工具 cron表达式工具 密码生成工具

京公网安备 11010502049817号