首页 > 其他分享 >vue3+TS+vite实现瀑布流列表

vue3+TS+vite实现瀑布流列表

时间:2024-09-02 20:25:34浏览次数:3  
标签:vue const TS rowPerView loading vue3 import displayName vite

安装依赖

npm install vue-waterfall-plugin-next

vue文件中引入使用

<script setup lang="ts">
import { RouterLink } from 'vue-router'
import { Waterfall } from 'vue-waterfall-plugin-next'
import 'vue-waterfall-plugin-next/dist/style.css'
import { ref } from 'vue'
import { readCategoryTree } from '@/api/ele'
import { useAppStore } from '@/stores/app'

interface ICategoryTree {
  name: string
  displayName: string
  icon: boolean
  count: number
  children: ICategoryTree[]
}

const store = useAppStore()

const breakpoints = {
  9999: { rowPerView: 4 },
  1200: { rowPerView: 3 },
  800: { rowPerView: 2 },
  500: { rowPerView: 1 }
}

const loading = ref<boolean>(false)

const categoryData = ref<ICategoryTree[]>([])

function getCategoryTree() {
  loading.value = true
  readCategoryTree(store.language)
    .then((res) => {
      categoryData.value = res.data
    })
    .finally(() => {
      loading.value = false
    })
}

getCategoryTree()
</script>
<template>
  <div class="bg-gray-200 min-h-60" v-loading="loading">
    <div class="mx-auto max-w-7xl pb-4">
      <Waterfall :list="categoryData" :breakpoints="breakpoints" :gutter="10">
        <template #default="{ item, url, index }">
          <div class="bg-white rounded-lg min-h-48 px-6 py-6">
            <!-- 一级 -->
            <div class="flex flex-row pb-2">
              <RouterLink to="#" class="font-bold flex-grow"> {{ item.displayName }}</RouterLink>
              <img
                class="absolute right-2 top-4 h-16"
                v-if="item.icon"
                :src="'/api/v1/categories/' + item.name + '/icon'"
              />
            </div>
            <div
              v-for="(item1, index1) in item.children"
              :key="index1"
              class="text-sm text-gray-700 mb-1"
            >
              <RouterLink
                :to="{ name: 'parts', params: { name: item1.name, name2: item1.displayName } }"
                class="cursor-pointer"
              >
                {{ item1.displayName }}
              </RouterLink>
              <div v-for="(v, i) in item1.children" class="ps-4" :key="i">
                <RouterLink
                  :to="{ name: 'parts', params: { name: item1.name, name2: item1.displayName } }"
                  class="cursor-pointer"
                >
                  {{ v.displayName }}
                </RouterLink>
              </div>
            </div>
          </div>
        </template>
      </Waterfall>
    </div>
  </div>
</template>

 

标签:vue,const,TS,rowPerView,loading,vue3,import,displayName,vite
From: https://www.cnblogs.com/Console-LIJIE/p/18393462

相关文章

  • Vue3的学习---12
    12.AJAX与Axios框架12.1AJAX基础12.1.1AJAX简介AJAX(AsynchronousJavaScriptandXML)是一种在无需重新加载整个网页的情况下,能够更新部分网页的技术。通过AJAX,网页应用程序能够快速地与服务器进行异步通信,从而提高用户体验。AJAX的工作原理:创建XMLHttpRequest对象:这是AJA......
  • vue3+vite注册动态路由的实践
    //route/index.jsimport{createRouter,createWebHistory}from'vue-router'importHomeViewfrom'../views/HomeView.vue'//constcomp=()=>import('../views/AboutView.vue')//console.log('comp:>>......
  • 十大时间序列模型最强总结(九)贝叶斯结构时间序列模型(BSTS)
    九、贝叶斯结构时间序列模型(BSTS)1.原理BSTS模型是基于贝叶斯框架的时间序列建模方法,它允许对时间序列数据中的趋势、季节性和假期效应进行建模。BSTS模型结合了结构时间序列模型和贝叶斯推断方法,以提供灵活的建模能力。2.核心公式推导:趋势:使用随机游走模型或加法趋势模型。季......
  • Vue3 ref 和 reactive 的区别
    Vue3ref和reactive的区别文章目录Vue3ref和reactive的深度解析一、ref和reactive是什么二、vue3中如何使用ref和reactive三、ref和reactive包含哪些属性或方法API四、扩展与高级技巧五、优点与缺点六、对应“八股文”或面试常问问题七、总结与展望Vue3ref和......
  • H5 Morvin高颜值后台管理模板、html5+bootstrap5后台管理前端模板网站模板
    介绍推荐一个高颜值的应用模板,Morvin是一个基于Bootstrap5实现的后台管理系统模板。基于简单的和模块化的设计,这使得它很容易定制。这套后台模板有大量的可重用的和漂亮的UI元素,小部件等。帮助你的团队移动更快,节约开发成本,可以创建任何网站的后台数据管理,或者WEB应用系统的界......
  • ECharts实现雷达图详解
    ECharts是一款由百度开源的数据可视化工具,它提供了丰富的图表类型,如折线图、柱状图、饼图、散点图、雷达图、地图、K线图、热力图、仪表盘等,以及丰富的交互功能。ECharts组件的核心功能实现原理主要包括以下几个方面:数据驱动:ECharts采用数据驱动的设计理念,图表的生成和更新......
  • Android 9.0 内置google tts语音包功能实现
    1.前言 在9.0的产品开发中,在gms的相关项目对于文字转语音包功能不是内置功能,需要自己下载google的tts语音包,然后内置,在设置googletts语音包apk作为默认的tts语音引擎功能,接下来分析实现这个功能2.内置googletts语音包功能实现的核心类frameworks/base/core/java/androi......
  • OpenAI-Agents: 人工智能代理的力量与科技搜索的新方向
    OpenAI-Agents:人工智能代理的力量与科技搜索的新方向在人工智能快速发展的今天,OpenAI-Agents项目为我们展示了AI在生成高质量文本和理解复杂主题方面的惊人能力。这个由AI完全撰写的应用程序和论文集合,不仅体现了人工智能的潜力,更为科研和技术探索开辟了新的方向。让我们深......
  • EXISTS
    EXISTS是SQL中用来检查子查询中是否有结果返回的谓词。它通常用在WHERE子句中,用来根据子查询是否有结果来决定外部查询的结果。当子查询至少返回一行时,EXISTS返回TRUE,否则返回FALSE。 EXISTS适合用来检查某个条件是否满足,而不需要知道满足条件的具体行。基本用法......
  • 鸿蒙跨端实践-ArkTS和CAPI的混合开发实现
    一、背景在动态化-鸿蒙跨端方案文章中,讲述了动态化适配鸿蒙的方案实现,当在鸿蒙系统进行UI渲染的时候,我们使用了系统的组件进行递归渲染。在iOS和Android也是借助各自系统组件进行的渲染,但是在鸿蒙系统会存在以下4个严重问题:1.UI层级过多以金融APP理财频道页中的一个乐高楼层中的“......