Vue 生成不重复的id & 动画

一.生成不重复的id

import {nanoid} from 'nanoid'
const todoObj = {id:nanoid(),title:this.title,done:false}

二.动画

1. 操作 css 的 trasition 或 animation
2. vue 会给目标元素添加/移除特定的 class
3. 过渡的相关类名:
     1). xxx-enter-active: 指定显示的 transition
     2). xxx-leave-active: 指定隐藏的 transition
     3). xxx-enter/xxx-leave-to: 指定隐藏时的样式


3.9.3 基本过渡动画的编码
1. 在目标元素外包裹<transition name="xxx">
2. 定义 class 样式
a) 指定过渡样式: transition
b) 指定隐藏时的样式: opacity/其它

动画实例

1. 用 transition 包裹动画标签,

appear属性 :  vue动画appear 实现页面刚展示出来的时候,入场效果

<template>
	<div>
		<button @click="isShow = !isShow">显示/隐藏</button>
		<transition name="hello" appear>
			<h1 v-show="isShow">你好啊!</h1>
		</transition>
	</div>
</template>

 多个动画效果,用 transition-group,并且key不能重复

<transition-group name="hello" appear>
 <h1 v-show="!isShow" key="1">你好啊!</h1>
 <h1 v-show="isShow" key="2">尚硅谷!</h1>
</transition-group>

有一篇很好的Vue——过渡与动画__洋的博客-CSDN博客

  • 0
    点赞
  • 0
    收藏
    觉得还不错? 一键收藏
  • 0
    评论
Vue生成雪花ID可以使用snowflake算法。Snowflake算法是一种分布式唯一ID生成算法,它可以在多个节点上生成重复ID。以下是一个示例代码,用于在Vue生成雪花ID: ```javascript // snowflake.js class Snowflake { constructor(datacenterId, workerId) { this.twepoch = 1288834974657n; this.datacenterId = BigInt(datacenterId); this.workerId = BigInt(workerId); this.sequence = 0n; this.workerIdBits = 5n; this.datacenterIdBits = 5n; this.maxWorkerId = -1n ^ (-1n << this.workerIdBits); this.maxDatacenterId = -1n ^ (-1n << this.datacenterIdBits); this.sequenceBits = 12n; this.workerIdShift = this.sequenceBits; this.datacenterIdShift = this.sequenceBits + this.workerIdBits; this.timestampLeftShift = this.sequenceBits + this.workerIdBits + this.datacenterIdBits; this.sequenceMask = -1n ^ (-1n << this.sequenceBits); this.lastTimestamp = -1n; } nextId() { let timestamp = BigInt(Date.now()); if (timestamp < this.lastTimestamp) { throw new Error('Invalid system clock'); } if (timestamp === this.lastTimestamp) { this.sequence = (this.sequence + 1n) & this.sequenceMask; if (this.sequence === 0n) { timestamp = this.tilNextMillis(this.lastTimestamp); } } else { this.sequence = 0n; } this.lastTimestamp = timestamp; return ((timestamp - this.twepoch) << this.timestampLeftShift) | (this.datacenterId << this.datacenterIdShift) | (this.workerId << this.workerIdShift) | this.sequence; } tilNextMillis(lastTimestamp) { let timestamp = BigInt(Date.now()); while (timestamp <= lastTimestamp) { timestamp = BigInt(Date.now()); } return timestamp; } } export default Snowflake; ``` 然后,在你的Vue组件中使用这个Snowflake类生成雪花ID: ```javascript <template> <div> <button @click="generateId">Generate Snowflake ID</button> <p>{{ snowflakeId }}</p> </div> </template> <script> import Snowflake from './snowflake'; export default { data() { return { snowflakeId: null, }; }, methods: { generateId() { const snowflake = new Snowflake(1, 1); // 传入datacenterId和workerId this.snowflakeId = snowflake.nextId().toString(); }, }, }; </script> ``` 这样,当你点击"Generate Snowflake ID"按钮时,就会生成一个唯一的雪花ID,并且将其显示在页面上。请根据你的需求修改datacenterId和workerId参数。

“相关推荐”对你有帮助么?

  • 非常没帮助
  • 没帮助
  • 一般
  • 有帮助
  • 非常有帮助
提交
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

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

余额充值