vue3.0翻牌數(shù)字組件使用方法詳解
本文實例為大家分享了vue3.0翻牌數(shù)字組件使用的具體代碼,供大家參考,具體內(nèi)容如下
代碼
<template> ? <div class="number-count-wrap" :class="numberSize"> ? ? <!-- 標(biāo)題 start --> ? ? <div class="number-title" :style="{'text-align': titleAlign}">{{title}}</div> ? ? <!-- 標(biāo)題 end --> ? ? <div class="number-count" :class="numberAlign"> ? ? ? <!-- 計數(shù)器 start --> ? ? ? <ul class="number-content"> ? ? ? ? <template v-for="(item,index) in orderNum" ? ? ? ? ? :key="index"> ? ? ? ? <li class="number-item" v-if="!isNaN(item)"> ? ? ? ? ? <span> ? ? ? ? ? ? <ul class="number-list" :ref="numberItem"> ? ? ? ? ? ? ? <li>0</li> ? ? ? ? ? ? ? <li>1</li> ? ? ? ? ? ? ? <li>2</li> ? ? ? ? ? ? ? <li>3</li> ? ? ? ? ? ? ? <li>4</li> ? ? ? ? ? ? ? <li>5</li> ? ? ? ? ? ? ? <li>6</li> ? ? ? ? ? ? ? <li>7</li> ? ? ? ? ? ? ? <li>8</li> ? ? ? ? ? ? ? <li>9</li> ? ? ? ? ? ? </ul> ? ? ? ? ? </span> ? ? ? ? </li> ? ? ? ? <li class="separator" v-else> ? ? ? ? ? {{item}} ? ? ? ? </li> ? ? ? ? </template> ? ? ? </ul> ? ? ? <!-- 計數(shù)器 end --> ? ? ? <!-- 單位 start --> ? ? ? <div class="number-unit" v-if="unit">{{unit}}</div> ? ? ? <!-- 單位 end --> ? ? </div> ? </div> </template> <script> import { onMounted, watch, ref, reactive, toRefs } from 'vue' export default { ? name: "numberCount", ? props: { ? ? numberSize: { // 字號大小 middle 中號 small 小號 ? ? ? type: String, ? ? ? default: '' ? ? }, ? ? title: { // 標(biāo)題 ? ? ? type: String, ? ? ? default: "" ? ? }, ? ? titleAlign: { // 標(biāo)題對齊方式 ? ? ? type: String, ? ? ? default: '' ? ? }, ? ? numberAlign: { //數(shù)字對齊方式 ? ? ? type: String, // center 居中對齊 ? ? ? default: '' ? ? }, ? ? unit: { // 單位 ? ? ? type: String, ? ? ? default: "" ? ? }, ? ? countNum: { // 數(shù)值 ? ? ? type: Number, ? ? }, ? ? initDelay: { // 首次加載延時 ? ? ? type: Number, ? ? } ? }, ? setup(props) { ? ? const numberItemList = ref([]); ? ? const numberItem = (el) => { ? ? ? numberItemList.value.push(el); ? ? }; ? ? var locarCountNum = props.countNum.toLocaleString() ? ? locarCountNum = locarCountNum.split('') ? ? const data = reactive({ ? ? ? orderNum: locarCountNum, // 默認(rèn)訂單總數(shù) ? ? }); ? ? watch(props, (nval, oval) => { ? ? ? if (nval) { ? ? ? ? toOrderNum(nval.countNum) ? ? ? } ? ? }) ? ? onMounted(() => { ? ? ? setTimeout(() => { ? ? ? ? toOrderNum(props.countNum) // 這里輸入數(shù)字即可調(diào)用 ? ? ? }, props.initDelay); ? ? }) ? ? function setNumberTransform () { ? ? ? const numberItems = numberItemList.value // 拿到數(shù)字的ref,計算元素數(shù)量 ? ? ? const numberArr = data.orderNum.filter(item => !isNaN(item)) ? ? ? // 結(jié)合CSS 對數(shù)字字符進行滾動,顯示訂單數(shù)量 ? ? ? for (let index = 0; index < numberItems.length; index++) { ? ? ? ? const elem = numberItems[index] ? ? ? ? elem.style.transform = `translate(0%, -${numberArr[index] * 10}%)` ? ? ? } ? ? } ? ? // 處理總訂單數(shù)字 ? ? function toOrderNum(num) { ? ? ? // console.log('num',num) ? ? ? // num = num.toString() ? ? ? // 把訂單數(shù)變成字符串 ? ? ? // if (num.length < 7) { ? ? ? // ? num = '0' + num // 如未滿八位數(shù),添加"0"補位 ? ? ? // ? toOrderNum(num) // 遞歸添加"0"補位 ? ? ? // } else if (num.length === 7) { ? ? ? // ? // 訂單數(shù)中加入逗號 ? ? ? // ? // num = num.slice(0, 2) + ',' + num.slice(2, 5) + ',' + num.slice(5, 8) ? ? ? // ? data.orderNum = num.split('') // 將其便變成數(shù)據(jù),渲染至滾動數(shù)組 ? ? ? // } else { ? ? ? // ? // 訂單總量數(shù)字超過八位顯示異常 ? ? ? // ? // _this.$message.warning('總量數(shù)字過大') ? ? ? // } ? ? ? setNumberTransform() ? ? } ? ? return { ? ? ? setNumberTransform, ? ? ? toOrderNum, ? ? ? numberItem, ? ? ? ...toRefs(data) ? ? } ? } }; </script> <style scoped lang="less"> .number-count-wrap { ? .number-title { ? ? font-size: .18rem; ? ? color: #FFFFFF; ? ? line-height: 1; ? ? margin-bottom: .15rem; ? ? font-weight: bold; ? } ? .number-count { ? ? display: flex; ? ? justify-content: flex-start; ? ? align-items: flex-end; ? ? .number-content { ? ? ? display: flex; ? ? ? justify-content: flex-start; ? ? ? align-items: center; ? ? ? ? /*文字禁止編輯*/ ? ? ? -moz-user-select: none; /*火狐*/ ? ? ? -webkit-user-select: none; /*webkit瀏覽器*/ ? ? ? -ms-user-select: none; /*IE10*/ ? ? ? -khtml-user-select: none; /*早期瀏覽器*/ ? ? ? user-select: none; ? ? ? .number-item { ? ? ? ? width: 0.32rem; ? ? ? ? // height: 1.8rem; ? ? ? ? display: flex; ? ? ? ? justify-content: center; ? ? ? ? align-items: center; ? ? ? ? margin: 0 0.02rem; ? ? ? ? &>span { ? ? ? ? ? position: relative; ? ? ? ? ? display: inline-block; ? ? ? ? ? width: 100%; ? ? ? ? ? height: 0.4rem; ? ? ? ? ? overflow: hidden; ? ? ? ? ? background: linear-gradient(180deg, #2167D0 0%, #164D8F 100%); ? ? ? ? ? box-shadow: 0 .04rem 0 0 #176ED6; ? ? ? ? ? border-radius: .06rem; ? ? ? ? ? border: 1px solid white; ? ? ? ? ? padding-bottom: .04rem; ? ? ? ? ? box-sizing: border-box; ? ? ? ? ? .number-list{ ? ? ? ? ? ? transition: transform 1s ease-in-out; ? ? ? ? ? ? text-align: center; ? ? ? ? ? ? font-weight: 600; ? ? ? ? ? ? li { ? ? ? ? ? ? ? height: 0.4rem; ? ? ? ? ? ? ? display: flex; ? ? ? ? ? ? ? justify-content: center; ? ? ? ? ? ? ? align-items: center; ? ? ? ? ? ? ? font-size: .3rem; ? ? ? ? ? ? ? font-weight:400; ? ? ? ? ? ? ? color: white; ? ? ? ? ? ? ? padding-bottom: .04rem; ? ? ? ? ? ? ? box-sizing: border-box; ? ? ? ? ? ? } ? ? ? ? ? } ? ? ? ? } ? ? ? } ? ? ? .separator { ? ? ? ? font-size: .3rem; ? ? ? ? font-weight: normal; ? ? ? ? color: #FFFFFF; ? ? ? ? line-height: 1; ? ? ? ? margin: 0 0.025rem; ? ? ? } ? ? } ? ? .number-unit { ? ? ? margin-left: .1rem; ? ? ? font-size: .18rem; ? ? ? font-weight: normal; ? ? ? color: #B1B7BC; ? ? } ? } ? .center { ? ? justify-content: center; ? } } // middle start .middle { ? .number-title { ? ? font-size: .12rem; ? ? margin-bottom: .10rem; ? } ? .number-count { ? ? .number-content { ? ? ? .number-item { ? ? ? ? width: 0.2rem; ? ? ? ? margin: 0 0.0175rem; ? ? ? ? &>span { ? ? ? ? ? height: 0.25rem; ? ? ? ? ? box-shadow: 0 .025rem 0 0 #176ED6; ? ? ? ? ? border-radius: .04rem; ? ? ? ? ? padding-bottom: .025rem; ? ? ? ? ? .number-list{ ? ? ? ? ? ? li { ? ? ? ? ? ? ? height: 0.25rem; ? ? ? ? ? ? ? font-size: .2rem; ? ? ? ? ? ? ? font-weight:400; ? ? ? ? ? ? ? color: white; ? ? ? ? ? ? ? box-sizing: border-box; ? ? ? ? ? ? } ? ? ? ? ? } ? ? ? ? } ? ? ? } ? ? ? .separator { ? ? ? ? font-size: .2rem; ? ? ? ? margin: 0 0.025rem; ? ? ? } ? ? } ? ? .number-unit { ? ? ? margin-left: .06rem; ? ? ? font-size: .12rem; ? ? } ? } } // middle end </style>
以上就是本文的全部內(nèi)容,希望對大家的學(xué)習(xí)有所幫助,也希望大家多多支持腳本之家。
相關(guān)文章
Vue的v-model的幾種修飾符.lazy,.number和.trim的用法說明
這篇文章主要介紹了Vue的v-model的幾種修飾符.lazy,.number和.trim的用法說明,具有很好的參考價值,希望對大家有所幫助。一起跟隨小編過來看看吧2020-08-08vue中的echarts實現(xiàn)寬度自適應(yīng)的解決方案
這篇文章主要介紹了vue中的echarts實現(xiàn)寬度自適應(yīng),本文給大家分享實現(xiàn)方案,代碼簡單易懂,對大家的學(xué)習(xí)或工作具有一定的參考借鑒價值,需要的朋友可以參考下2022-09-09vue使用tracking實現(xiàn)人臉識別/人臉偵測完整代碼
作為一個AI模型,人臉識別涉及到多個技術(shù)領(lǐng)域,下面這篇文章主要給大家介紹了關(guān)于vue使用tracking實現(xiàn)人臉識別/人臉偵測的相關(guān)資料,文中通過代碼介紹的非常詳細(xì),需要的朋友可以參考下2023-09-09ResizeObserver?loop?limit?exceeded報錯原因及解決方案
這篇文章主要給大家介紹了關(guān)于ResizeObserver?loop?limit?exceeded報錯原因及解決的相關(guān)資料,公司項目監(jiān)聽系統(tǒng)中發(fā)現(xiàn)一個高頻錯誤ResizeObserver loop limit exceeded,而瀏覽器的console中卻沒有提示,需要的朋友可以參考下2023-09-09使用Bootstrap + Vue.js實現(xiàn)表格的動態(tài)展示、新增和刪除功能
這篇文章主要介紹了使用Bootstrap + Vue.js實現(xiàn)表格的動態(tài)展示、新增和刪除功能,需要的朋友可以參考下2017-11-11vue.js實現(xiàn)含搜索的多種復(fù)選框(附源碼)
這篇文章主要給大家介紹了利用vue.js實現(xiàn)含搜索的多種復(fù)選框的相關(guān)資料,文中給出了簡單的介紹,但提供了完整的實例源碼供大家下載學(xué)習(xí),相信對大家具有一定的參考價值,需要的朋友們下面來一起看看吧。2017-03-03