vue3-实现点击右侧标签显示内容

在TagCloud.vue中添加链接,如下:

<script setup>
import { ref } from "vue";
 
const tags=ref([]);
const tagSet=new Set();
const props = defineProps({
    posts:Array,  
});
console.log(props.posts);
alert(props.posts.length);
props.posts.forEach((item)=>{
    item.tags.forEach((tag)=>
        tagSet.add(tag)
    )
});
tags.value=[...tagSet];
 
</script>
 
<template>
    <div class="tag-cloud">
        <h3>标签</h3>
        <div v-for="tag in tags" :key="tag">
        <router-link :to="{name:'Tag',params:tag}">#{{tag}}</router-link>
        </div>
    </div>
</template>
 
<style scoped>
.tag-cloud{
    padding:10px;
}
.tag-cloud h3{
    border-bottom:1px solid #eee;
    padding:16px 8px;
    color:#444;
}
.tag-cloud div{
    display: inline-block;
    padding:10px;
 
}
.tag-cloud a{
    color:#ccc;
    text-decoration: none;
}
</style>

在views文件夹下创建Tag.vue组件,如下:

<script setup>
import {ref} from "vue";

</script>
 
<template>
  <div>tag</div>
</template>
 
<style scoped>

</style>

在index.js中添加这个路由:

    import {createRouter,createWebHistory} from "vue-router";
    import Home from "../views/Home.vue";
    import Details from "../views/Details.vue";
    import Create from "../views/Create.vue";
    import Tag from "../views/Tag.vue";

    const routes=[
    {path:"/",name:"Home",component:Home},
    {path:"/posts/:id",name:"Details",component:Details,props:true},
    {path:"/create",name:"Create",component:Create},
    {path:"/tag",name:"Tag",component:Tag},
    ];
    const router=createRouter({
        history:createWebHistory(),
        routes

    })
    export default router;

  • 0
    点赞
  • 1
    收藏
    觉得还不错? 一键收藏
  • 打赏
    打赏
  • 0
    评论
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包

打赏作者

爱人间

你的鼓励将是我创作的最大动力

¥1 ¥2 ¥4 ¥6 ¥10 ¥20
扫码支付:¥1
获取中
扫码支付

您的余额不足,请更换扫码支付或充值

打赏作者

实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值