正计时cpr

这个博客展示了如何在Vue.js中创建一个倒计时组件。代码包括一个模板,其中包含用于显示小时、分钟和秒数的计时器卡片,以及在`created`钩子中启动的`testTimer`方法,该方法每秒更新时间并调整显示。`timeFunction`方法处理倒计时的计算,确保数值在00到59之间,并提供了清除定时器的条件,虽然在这个例子中未实际使用。
<template>
    <div id="app">

        <div class="timer-div dowebok">
            <div class="timer">
                <div class="time-card" data-type="hours" data-max="24">
                    <div class="time-card-count">{{myHours}}</div>
                </div>
                <span class="colon">:</span>
                <div class="time-card" data-type="minutes" data-max="60">
                    <div class="time-card-count">{{myMinutes}}</div>
                </div>
                <span class="colon">:</span>
                <div class="time-card" data-type="seconds" data-max="60">
                    <div class="time-card-count">{{mySeconds}}</div>
                </div>
            </div>
        </div>

    </div>
</template>

<script>
    export default {
        name: 'App',
        data() {
            return {
                currentTime: 0,
                timeObj: null, // 时间对象,下方会用到
                myHours: '00', // 我定义来接收计算出来的 小时 的
                myMinutes: '00', // 我定义来接收计算出来的 分钟 的
                mySeconds: '00',// 我定义来接收计算出来的 秒钟 的
                testTimeClear:''
            }
        },
        created() {
            this.testTimer()
        },
        methods: {
            testTimer() {
                this.timeFunction();
                this.testTimeClear = setInterval(() => {
                    this.timeFunction();
                }, 1000)
            },
            timeFunction() {
                // 开始执行倒计时
                this.timeObj = { // 时间对象
                    seconds: Math.floor(this.currentTime % 60),
                    minutes: Math.floor(this.currentTime / 60) % 60,
                    hours: Math.floor(this.currentTime / 60 / 60) % 24
                }
                // 计算出时分秒
                this.myHours = this.timeObj.hours < 10 ? '0' + this.timeObj.hours : this.timeObj.hours;
                this.myMinutes = this.timeObj.minutes < 10 ? '0' + this.timeObj.minutes : this.timeObj.minutes;
                this.mySeconds = this.timeObj.seconds < 10 ? '0' + this.timeObj.seconds : this.timeObj.seconds;
                this.currentTime++;

                // if (this.myMinutes == '03' && this.mySeconds == '11') {
                //
                //     clearInterval(this.testTimeClear)
                //
                // }

            }
        }
    }
</script>


<style>
    .dowebok {
        margin-top: 200px;
        align-items: center;
    }

    .timer {
        display: flex;
        flex-direction: row;
        justify-content: center;
        align-items: center;
        margin: 0 0 4em;
        color: #151414;
    }

    .time-card {
        margin: 0 1em;
        text-align: center;
    }

    .time-card-count {
        font-weight: 600;
        font-size: 50px;
        width: 77px;
        height: 77px;
        line-height: 77px;
        overflow: hidden;
    }

    .colon {
        font-size: 2em;
    }
</style>

06-18
### CPR编程库工具 CPR 是一个用于简化 HTTP 请求的 C++ 库,它的全称是 **C++ Requests**。该库的设计灵感来源于 Python 的 `requests` 库[^1],旨在为 C++ 开发者提供一种简单且直观的方式来发送 HTTP 请求并处理响应。 以下是 CPR 的一些关键特性: - 支持多种 HTTP 方法(如 GET、POST、PUT、DELETE 等)。 - 提供同步和异步请求功能。 - 允许设置请求头、查询参数、表单数据和 JSON 数据。 - 支持文件上传和下载。 - 可以通过插件扩展功能,例如添加日志记录或修改请求行为。 以下是一个使用 CPR 库发送 GET 请求的示例代码: ```cpp #include <cpr/cpr.h> #include <iostream> int main() { cpr::Response r = cpr::Get(cpr::Url{"https://httpbin.org/get"}, cpr::Parameters{{"hello", "world"}}); std::cout << r.text << std::endl; // 输出响应内容 return 0; } ``` 此外,CPR 依赖于其他第三方库,例如 `libcurl` 和 `Boost`,这些库提供了底层网络通信支持和高级功能实现[^2]。 ### 安装与配置 CPR 可以通过多种方式安装,包括使用包管理器(如 vcpkg 或 Conan)或者手动编译源代码。对于开发者来说,推荐使用包管理器来简化依赖管理过程。 #### 使用 vcpkg 安装 CPR: ```bash vcpkg install cpr ``` #### 使用 Conan 安装 CPR: ```bash conan install cpr/1.9.0 ``` ### 应用场景 CPR 在需要进行网络通信的 C++ 应用程序中非常有用,例如: - Web API 客户端开发。 - 数据抓取和分析。 - 文件传输和远程服务交互。 ### 注意事项 在使用 CPR 时需要注意以下几点: - 确保确配置依赖库(如 libcurl),否则可能会导致编译或运行时错误。 - 异步请求需要额外的线程管理,开发者应小心避免潜在的并发问题[^3]。
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

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

抵扣说明:

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

余额充值