vue 工具类 publicUtil

 1.全局引用

import publicUtils from '@/util/publicUtil';
Vue.prototype.publicUtils = publicUtils;

2.工具类编写


export default {
    getSize(val) {
        var KB = val / 1024;
        var MB = KB / 1024;
        if (MB < 1024) {
            return `${MB.toFixed(2)}MB`;
        } else {
            let GB = MB / 1024;
            if (GB < 1024) {
                return `${GB.toFixed(2)}GB`;
            } else {
                return `${(GB / 1024).toFixed(2)}TB`;
            }
        }
    },

    getProportion(width, height) {
        if (height && width) {
            return `${width} * ${height}`
        }
        return ``;
    },

    padZero(number) {
        return number < 10 ? '0' + number : number;
    },

    timeFormat(seconds) {
        var hours = Math.floor(seconds / 3600);
        var minutes = Math.floor((seconds % 3600) / 60);
        var remainingSeconds = seconds % 60;

        // 在小时、分钟、秒数小于10时,在前面补零
        var formattedHours = this.padZero(hours);
        var formattedMinutes = this.padZero(minutes);
        var formattedSeconds = this.padZero(remainingSeconds);

        return formattedHours + ':' + formattedMinutes + ':' + formattedSeconds;
    }
}

3.具体页面

评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

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

抵扣说明:

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

余额充值