vue實(shí)現(xiàn)動(dòng)態(tài)列表尾部添加數(shù)據(jù)執(zhí)行動(dòng)畫
動(dòng)態(tài)列表尾部添加數(shù)據(jù)執(zhí)行動(dòng)畫
先上動(dòng)畫
- 動(dòng)態(tài)控制節(jié)點(diǎn)數(shù)量(目前只顯示6個(gè)節(jié)點(diǎn))
- 尾部添加幾個(gè)item,頭部則刪除幾個(gè)item
- 觸發(fā) transition-group 動(dòng)畫
- splice 的使用方法
代碼:
<style lang="scss"> .content { ? display: flex; ? width: 600px; ? height: 50px; ? margin: 100px auto; } .list-complete-item { ? transition: all 1s; ? display: inline-block; ? width: 100px; ? text-align: center; ? line-height: 50px; ? font-size: 18px; } .list-complete-enter, .list-complete-leave-to { ? opacity: 0; ? transform: translateX(-30px); } .list-complete-leave-active { ? position: absolute; } </style>
<template> ? <div class="vueBox"> ? ? <transition-group class="content" name="list-complete" tag="div"> ? ? ? <span ? ? ? ? v-for="item in list" ? ? ? ? v-bind:key="item.value" ? ? ? ? class="list-complete-item" ? ? ? > ? ? ? ? {{ item.name }} ? ? ? </span> ? ? </transition-group> ? </div> </template>
<script> export default { ? name: "slideanimation", ? data() { ? ? return { ? ? ? list: [ ? ? ? ? { ? ? ? ? ? name: "蘋果", ? ? ? ? ? value: "1.68", ? ? ? ? }, ? ? ? ? { ? ? ? ? ? name: "橘子", ? ? ? ? ? value: "0.9", ? ? ? ? }, ? ? ? ? { ? ? ? ? ? name: "香蕉", ? ? ? ? ? value: "2.58", ? ? ? ? }, ? ? ? ? { ? ? ? ? ? name: "獼猴桃", ? ? ? ? ? value: "3.2", ? ? ? ? }, ? ? ? ? { ? ? ? ? ? name: "靈夢", ? ? ? ? ? value: "1.2", ? ? ? ? }, ? ? ? ? { ? ? ? ? ? name: "李子", ? ? ? ? ? value: "13.2", ? ? ? ? }, ? ? ? ], ? ? }; ? }, ? mounted() { ? ? // 定時(shí)模擬的socket的 推送數(shù)據(jù), 需求: 頁面只顯示6個(gè)節(jié)點(diǎn),推送幾個(gè)新的數(shù)據(jù),則刪除頭部幾個(gè)數(shù)組。 ? ? setInterval(() => { ? ? ? this.animation(); ? ? }, 3000); ? }, ? methods: { ? ? // 生成指定 隨機(jī)范圍的 整數(shù) ? ? randomNum(minNum, maxNum) { ? ? ? switch (arguments.length) { ? ? ? ? case 1: ? ? ? ? ? return parseInt(Math.random() * minNum + 1, 10); ? ? ? ? ? break; ? ? ? ? case 2: ? ? ? ? ? return parseInt(Math.random() * (maxNum - minNum + 1) + minNum, 10); ? ? ? ? ? break; ? ? ? ? default: ? ? ? ? ? return 0; ? ? ? ? ? break; ? ? ? } ? ? }, ? ? animation() { ? ? ? let newItems = [...this.list]; ? ? ? // 來一波隨機(jī)個(gè)數(shù),隨機(jī)數(shù)組 ? ? ? let randomCount = 1, ? ? ? ? addItems = []; ? ? ? randomCount = this.randomNum(1, 3); ? ? ? console.info("生成隨機(jī)數(shù) - 尾部添加 - 頭部刪除", randomCount); ? ? ? Array.from(new Array(randomCount), (n, i) => i).forEach(() => ? ? ? ? addItems.push({ ? ? ? ? ? name: (Math.random(0, 1) * 1000).toFixed(0), ? ? ? ? ? value: Math.random(0, 1), ? ? ? ? }) ? ? ? ); ? ? ? // 刪除 數(shù)組 頭部 幾個(gè)item ? ? ? newItems.splice(0, randomCount); ? ? ? // 數(shù)組 尾部 添加 幾個(gè)item ? ? ? newItems.splice(newItems.length, 0, ...addItems); ? ? ? // 觸發(fā) transition-group 動(dòng)畫 ? ? ? this.list = [...newItems]; ? ? }, ? }, }; </script>
動(dòng)態(tài)數(shù)據(jù)使用wowjs顯示動(dòng)畫
1.通過npm安裝
npm install wowjs --save-dev
animate.css會(huì)自動(dòng)安裝。
2.在main.js中引入animate.css
import 'wowjs/css/libs/animate.css
在組件需要的地方引入wowjs
有兩種使用方式:
第一種:
import {WOW} from 'wowjs' ?? ? ? mounted() { ? ? ? new WOW().init() ? ? }
第二種:
import WOW from 'wowjs' ?? ? mounted() { ? ? ?new WOW.WOW().init() ? ?}
wow實(shí)例化里面的配置參數(shù)
自己選擇性添加配置參數(shù)
infinite無限次播放
如過添加動(dòng)畫的元素渲染數(shù)據(jù)是請求接口渲染的 那么實(shí)例化wow一定得在接口請求結(jié)束之后使用this.$nextTick()在這個(gè)函數(shù)里面執(zhí)行
以上為個(gè)人經(jīng)驗(yàn),希望能給大家一個(gè)參考,也希望大家多多支持腳本之家。
- Vue+elementUI實(shí)現(xiàn)動(dòng)態(tài)展示列表的數(shù)據(jù)
- vue?使用el-table循環(huán)輪播數(shù)據(jù)列表的實(shí)現(xiàn)
- vue如何從后臺(tái)獲取數(shù)據(jù)生成動(dòng)態(tài)菜單列表
- Vue3 列表界面數(shù)據(jù)展示詳情
- 使用Vue3進(jìn)行數(shù)據(jù)綁定及顯示列表數(shù)據(jù)
- vue列表數(shù)據(jù)刪除后主動(dòng)刷新頁面及刷新方法詳解
- vue2.0實(shí)現(xiàn)列表數(shù)據(jù)增加和刪除
- Vue如何獲取數(shù)據(jù)列表展示
- vue input輸入框關(guān)鍵字篩選檢索列表數(shù)據(jù)展示
- vue父列表數(shù)據(jù)獲取子列表數(shù)據(jù)的實(shí)現(xiàn)步驟
相關(guān)文章
使用elementUI表單校驗(yàn)函數(shù)validate需要注意的坑及解決
這篇文章主要介紹了使用elementUI表單校驗(yàn)函數(shù)validate需要注意的坑及解決,具有很好的參考價(jià)值,希望對大家有所幫助,如有錯(cuò)誤或未考慮完全的地方,望不吝賜教2024-06-06Vue實(shí)現(xiàn)右鍵菜單組件的超詳細(xì)教程(支持快捷鍵)
右鍵菜單組件非常常見,所有的前端開發(fā)工程師都會(huì)遇到類似的功能組件開發(fā)需求,這篇文章主要給大家介紹了關(guān)于Vue實(shí)現(xiàn)右鍵菜單組件的超詳細(xì)教程,文中介紹的方法支持快捷鍵,需要的朋友可以參考下2024-02-02vue設(shè)置頁面超時(shí)15分鐘自動(dòng)退出登錄的方法詳解
當(dāng)用戶登錄后,如果長時(shí)間未操作頁面這個(gè)時(shí)候需要自動(dòng)退出登錄回到登錄頁面,本文將給大家介紹一下vue設(shè)置頁面超時(shí)15分鐘自動(dòng)退出登錄的方法,感興趣的同學(xué)可以自己動(dòng)手試一下2023-10-10使用Vue.$set()或者Object.assign()修改對象新增響應(yīng)式屬性的方法
vue代碼中,只要在data對象里定義的對象,賦值后,任意一個(gè)屬性值發(fā)生變化,視圖都會(huì)實(shí)時(shí)變化,這篇文章主要介紹了使用Vue.$set()或者Object.assign()修改對象新增響應(yīng)式屬性,需要的朋友可以參考下2022-12-12Vue使用CDN引用項(xiàng)目組件,減少項(xiàng)目體積的步驟
這篇文章主要介紹了Vue使用CDN引用項(xiàng)目組件,減少項(xiàng)目體積的步驟,幫助大家提高項(xiàng)目加載速度,感興趣的朋友可以了解下2020-10-10VUE+Java實(shí)現(xiàn)評論回復(fù)功能
這篇文章主要為大家詳細(xì)介紹了VUE+Java實(shí)現(xiàn)評論回復(fù)功能,文中示例代碼介紹的非常詳細(xì),具有一定的參考價(jià)值,感興趣的小伙伴們可以參考一下2022-04-04Vue Element UI + OSS實(shí)現(xiàn)上傳文件功能
這篇文章主要為大家詳細(xì)介紹了Vue Element UI + OSS實(shí)現(xiàn)上傳文件功能,文中示例代碼介紹的非常詳細(xì),具有一定的參考價(jià)值,感興趣的小伙伴們可以參考一下2019-07-07