长相思·罚站墙Vue

news2024/10/2 3:30:35

优化前

看效果图

Vue长相思

在这里插入图片描述



刚学Vue,正好在追剧,看到这个小案例觉得挺好玩的,第一天学,代码太简陋了

代码

<!DOCTYPE html>
<html lang="en">

<head>
    <meta charset="UTF-8">
    <meta name="viewport" content="width=device-width, initial-scale=1.0">
    <title>Document</title>
</head>
<script src="../vue.js"></script>
<style>
    .box {
        /* width: 1200px; */
        height: 500px;

        display: flex;
        flex-direction: column;

        border: rgb(235, 137, 137) solid 3px;
        border-radius: 33px;
    }

    h1,
    .title {
        text-align: center;
        background: linear-gradient(to right, red, rgb(183, 0, 255), blue);
        -webkit-background-clip: text;
        -webkit-text-fill-color: transparent;
    }

    .body {
        display: flex;
        justify-content: space-around;
        /* background-color: aqua; */
    }


    img {
        width: 200px;
        height: 300px;

    }

    .row {
        width: 210px;
        padding-right: 1%;
        border-right: 1px blueviolet dashed;
    }

    .row:last-child {
        padding-right: 20px;
        border-right: none;
    }

    h3 {
        text-align: center;
    }
</style>

<body>
    <div id="app">
        <div class="box">
            <h1 class="title">长相思追剧小游戏</h1>
            <div class="body">
                <div class="row1 row">
                    <img src="./img/张晚意.jpg" alt="">
                    <h3>苍玄 </h3>
                    <button @click="fn(1,0)">罚站+1</button>
                    <span>{{result}}:{{result_time}}min </span>
                    <button @click="fn(0,1)">坐下+1</button>
                </div>


                <div class="row2 row">

                    <img src="./img/相柳.jpg" alt="">
                    <h3> 相柳 </h3>
                    <button @click="fn(1,0)">罚站+1</button>
                    <span>{{result}}:{{result_time}}min </span>
                    <button @click="fn(0,1)">坐下+1</button>
                </div>
                <div class="row3 row">
                    <img src="./img/涂山璟.jpg" alt="">
                    <h3>涂山璟</h3>
                    <button @click="fn(1,0)">罚站+1</button>
                    <span>{{result}}:{{result_time}}min </span>
                    <button @click="fn(0,1)">坐下+1</button>
                </div>

                <div class="row4 row">
                    <img src="./img/赤水丰隆.jpg" alt="">
                    <h3>赤水丰隆</h3>
                    <button @click="fn(1,0)">罚站+1</button>
                    <span>{{result}}:{{result_time}}min </span>
                    <button @click="fn(0,1)">坐下+1</button>
                </div>
            </div>
        </div>
        <p style="margin-top:100px ;">罚站和坐下 可以变颜色</p>
    </div>
</body>


<script>
    const app = new Vue({
        el: '.row1',
        data: {
            result: '咋办',
            result_time: 0,
            fail_time: 0,
            succeed_time: 0,


        },
        methods: {
            fn(ft, st) {
                this.fail_time += ft;
                this.succeed_time += st
                this.result_time = this.fail_time - this.succeed_time
                if (this.result_time > 0) {
                    this.result = '罚站';

                }
                else {
                    this.result = "坐下";
                    this.result_time = -this.result_time
                }
                console.log(this);

            }
        }

    })


    const app2 = new Vue({
        el: '.row2',
        data: {
            result: '咋办',
            result_time: 0,
            fail_time: 0,
            succeed_time: 0,


        },
        methods: {
            fn(ft, st) {
                this.fail_time += ft;
                this.succeed_time += st
                this.result_time = this.fail_time - this.succeed_time
                if (this.result_time > 0) {
                    this.result = '罚站';

                }
                else {
                    this.result = "坐下";
                    this.result_time = -this.result_time
                }
                console.log(this);

            }
        }

    })
    const app3 = new Vue({
        el: '.row3',
        data: {
            result: '咋办',
            result_time: 0,
            fail_time: 0,
            succeed_time: 0,


        },
        methods: {
            fn(ft, st) {
                this.fail_time += ft;
                this.succeed_time += st
                this.result_time = this.fail_time - this.succeed_time
                if (this.result_time > 0) {
                    this.result = '罚站';

                }
                else {
                    this.result = "坐下";
                    this.result_time = -this.result_time
                }
                console.log(this);

            }
        }

    })
    const app4 = new Vue({
        el: '.row4',
        data: {
            result: '咋办',
            result_time: 0,
            fail_time: 0,
            succeed_time: 0,


        },
        methods: {
            fn(ft, st) {
                this.fail_time += ft;
                this.succeed_time += st
                this.result_time = this.fail_time - this.succeed_time
                if (this.result_time > 0) {
                    this.result = '罚站';

                }
                else {
                    this.result = "坐下";
                    this.result_time = -this.result_time
                }
                console.log(this);

            }
        }

    })

</script>

</html>



优化方向

1.“罚站”和“坐下”的颜色可以改变
2.块结构不对吧,row应该用li
3.笨笨地定义了4个对象,不然,点击人物按钮,其他任务的时长也会变;但肯定有优化的办法,就emmm,类似this.result++ 但是具体的还不会哎
4.每次刷新网页,之前的记录会保留下来,好像是设置DOM啥的,回头在复习一下,都忘记了

优化后

1.特意做了PK按钮,运用旋转,灵感来源用css制作三角形
2.使用v-for避免冗余
3.“罚站”和“坐下”的颜色可以改变
4.本地存储,下次打开还是有的

效果图

在这里插入图片描述

代码

<!DOCTYPE html>
<html lang="en">

<head>
    <meta charset="UTF-8">
    <meta name="viewport" content="width=device-width, initial-scale=1.0">
    <title>Document</title>
</head>
<script src="../vue.js"></script>
<link rel="stylesheet" href="../base.css">
<style>
    body {
        background-color: rgb(239, 237, 216);
    }

    .box {
        /* width: 1200px; */
        height: 500px;

        display: flex;
        flex-direction: column;

        border: rgb(235, 137, 137) solid 3px;
        border-radius: 33px;
    }

    h1,
    .title {
        text-align: center;
        background: linear-gradient(to right, red, rgb(183, 0, 255), blue);
        -webkit-background-clip: text;
        -webkit-text-fill-color: transparent;
        margin-bottom: 30px;
    }

    .body {
        display: flex;
        justify-content: space-around;
        /* background-color: aqua; */
    }


    img {
        width: 200px;
        height: 300px;

    }

    .punishment {
        color: red;
    }

    .reward {
        color: rgb(0, 208, 255);
    }

    h3 {
        text-align: center;
    }

    .text {
        display: block;
        width: 100%;
        text-align: center;
    }

    /* PK的按钮 */
    .btn_box {
        position: relative;
        margin: 10px auto;
        width: 120px;
        height: 40px;
        /* border: 1px black solid; */
        /* background-color: #b17a7a; */
        border-radius: 30px;
        overflow: hidden;
        border-radius: 30px;


    }

    .right {
        position: absolute;
        top: -2px;
        width: 110%;
        height: 110%;
        background-color: #ffffff;
        text-align: right;
        line-height: 40px;
        padding-right: 30px;
        color: #e94e4e;
        font-weight: bold;
        border: none;
    }

    .left {
        position: absolute;
        z-index: 2;
        width: 100%;
        height: 150%;
        background-color: #e94e4e;
        transform-origin: 31% 25%;
        transform: rotate(57deg);
        color: aliceblue;
        font-weight: bold;
        border: none;
        overflow: hidden;
    }

    .btn_box span {
        /* background-color: blueviolet; */
        display: block;
        width: 27px;
        transform-origin: 80% -80%;
        transform: rotate(302deg);
    }
</style>

<body>
    <div id="app">
        <div class="box">
            <h1 class="title">长相思· 角色罚站墙</h1>

            <!-- 主体 -->
            <div class="body">
                <div v-for="(item,index) in list">
                    <img :src="item.srcUrl">
                    <h3>{{item.name}} </h3>
                    <span class="text"
                        :class="{punishment:item.result_status=='罚站',reward:item.result_status=='坐下'}">{{item.result_status}}:{{item.result_time}}min</span>

                    <div class="btn_box">

                        <button @click="punishment(item)" class="left">
                            <span>罚站</span>
                        </button>
                        <button @click="reward(item)" class="right">坐下</button>
                    </div>
                </div>

            </div>
        </div>

    </div>
</body>


<script>
    const defaultArr = [
        { srcUrl: './img/张晚意.jpg', name: '玱玹', result_status: '坐下', result_time: 0, p_time: 0, r_time: 0 },
        { srcUrl: './img/相柳.jpg', name: '相柳', result_status: '坐下', result_time: 0, p_time: 0, r_time: 0 },
        { srcUrl: './img/涂山璟.jpg', name: '涂山璟', result_status: '坐下', result_time: 0, p_time: 0, r_time: 0 },
        { srcUrl: './img/赤水丰隆.jpg', name: '赤水丰隆', result_status: '坐下', result_time: 0, p_time: 0, r_time: 0 },
    ];
    const app = new Vue({
        el: '#app',
        data: {
            list: JSON.parse(localStorage.getItem('list')) || defaultArr,

        },
        methods: {
            punishment(item) {
                console.log('punish');

                item.p_time++;
                item.result_time = item.p_time - item.r_time;
                if (item.result_time > 0) {
                    item.result_status = '罚站'
                }
                else {
                    item.result_time = -item.result_time;
                    item.result_status = '坐下'
                }
            },
            reward(item) {
                console.log('reward');
                item.r_time++;
                item.result_time = item.p_time - item.r_time;
                if (item.result_time <= 0) {
                    item.result_time = -item.result_time;
                    item.result_status = '坐下'
                }
                else {
                    item.result_status = '罚站'
                }
            }


        },
        computed: {

        },
        watch: {
            list: {
                deep: true,
                handler(newValue) {
                    localStorage.setItem('list', JSON.stringify(newValue))


                }
            }
        },

    })


</script>

</html>

本文来自互联网用户投稿,该文观点仅代表作者本人,不代表本站立场。本站仅提供信息存储空间服务,不拥有所有权,不承担相关法律责任。如若转载,请注明出处:http://www.coloradmin.cn/o/836479.html

如若内容造成侵权/违法违规/事实不符,请联系多彩编程网进行投诉反馈,一经查实,立即删除!

相关文章

海外版金融理财系统源码 国际投资理财系统源码 项目投资理财源码

海外版金融理财系统源码 国际投资理财系统源码 项目投资理财源码

RF手机天线仿真介绍(三):调谐开关分析

目录 简介调谐开关RON、COFF的影响分析不同位置的调谐器件coff影响分析不同位置的调谐器件Ron影响分析Coff引起谐振的解决示例 调谐开关VPEAK分析调谐开关Vpeak示例 简介 孔径调谐能调节天线的电长度&#xff0c;可将其谐振点切换到所需支持的工作频段。天线孔径调谐器通过改变…

GPS/北斗RTK差分定位系统的原理以及应用领域

导语&#xff1a;现代定位技术在国内外的发展与应用越来越广泛&#xff0c;其中GPS和北斗是两大被广泛使用的全球卫星定位系统。本文将介绍GPS/北斗RTK差分定位系统的原理以及其在各个领域的应用。 一、GPS/北斗RTK差分定位系统的原理 GPS/北斗RTK差分定位系统&#xff0c;即全…

机器学习中的工作流机制

机器学习中的工作流机制 在项目开发的时候&#xff0c;经常需要我们选择使用哪一种模型。同样的数据&#xff0c;可能决策树效果不错&#xff0c;朴素贝叶斯也不错&#xff0c;SVM也挺好。有没有一种方法能够让我们用一份数据&#xff0c;同时训练多个模型&#xff0c;并用某种…

基于STM32103移植FreeRTOS

目录 一、FreeRTOS协议栈下载 二、准备工程文件与协议代码 三、移植FreeRTOS协议栈 一、FreeRTOS协议栈下载 1、官网下载 FreeRTOS - Market leading RTOS (Real Time Operating System) for embedded systems with Internet of Things extensionshttps://www.freertos.or…

SQL-每日一题【1193. 每月交易 I】

题目 Table: Transactions 编写一个 sql 查询来查找每个月和每个国家/地区的事务数及其总金额、已批准的事务数及其总金额。 以 任意顺序 返回结果表。 查询结果格式如下所示。 示例 1: 解题思路 1.题目要求我们查找每个月和每个国家/地区的事务数及其总金额、已批准的事务数…

Flutter(八)事件处理与通知

1.原始指针事件处理 一次完整的事件分为三个阶段&#xff1a;手指按下、手指移动、和手指抬起&#xff0c;而更高级别的手势&#xff08;如点击、双击、拖动等&#xff09;都是基于这些原始事件的。 Listener 组件 Flutter中可以使用Listener来监听原始触摸事件 Listener({…

Go语言开发者的Apache Arrow使用指南:读写Parquet文件

Apache Arrow是一种开放的、与语言无关的列式内存格式&#xff0c;在本系列文章[1]的前几篇中&#xff0c;我们都聚焦于内存表示[2]与内存操作[3]。 但对于一个数据库系统或大数据分析平台来说&#xff0c;数据不能也无法一直放在内存中&#xff0c;虽说目前内存很大也足够便宜…

FuncGPT竟然限免?!速来体验全球首个AIGF!

近日&#xff0c;飞算SoFlu软件机器人重磅推出全新功能——FuncGPT&#xff08;慧函数&#xff09;。FuncGPT&#xff08;慧函数&#xff09;是一款函数AI生产器&#xff0c;它能够根据用户的需求快速生成 Java 语言的函数代码。FuncGPT&#xff08;慧函数&#xff09;拥有强大…

行政资产管理信息系统

行政资产管理信息系统是通过专业设计开发的资产管理解决方案&#xff0c;旨在为企业建立和完善资产管理体系。该系统可以有效地控制资产的购买和应用&#xff0c;从而节省资金&#xff0c;完成资产的有效管理。   资产管理信息系统的核心功能是统一资产管理&#xff0c;可以…

java 版本企业招标投标管理系统源码+多个行业+tbms+及时准确+全程电子化

​ 功能描述 1、门户管理&#xff1a;所有用户可在门户页面查看所有的公告信息及相关的通知信息。主要板块包含&#xff1a;招标公告、非招标公告、系统通知、政策法规。 2、立项管理&#xff1a;企业用户可对需要采购的项目进行立项申请&#xff0c;并提交审批&#xff0c;查…

kernel pwn入门

Linux Kernel 介绍 Linux 内核是 Linux 操作系统的核心组件&#xff0c;它提供了操作系统的基本功能和服务。它是一个开源软件&#xff0c;由 Linus Torvalds 在 1991 年开始开发&#xff0c;并得到了全球广泛的贡献和支持。 Linux 内核的主要功能包括进程管理、内存管理、文…

2023-08-04 Untiy进阶 C#知识补充4——C#5主要功能与语法

文章目录 一、概述二、回顾——线程三、线程池四、Task 任务类五、同步和异步 ​ 注意&#xff1a;在此仅提及 Unity 开发中会用到的一些功能和特性&#xff0c;对于不适合在 Unity 中使用的内容会忽略。 一、概述 C# 5 调用方信息特性&#xff08;C# 进阶内容&#xff09;异步…

途乐证券|俄罗斯宣布9月削减石油出口量

当地时间周四&#xff0c;美股兜售潮仍在持续&#xff0c;三大股指连续第二个交易日团体收跌。到收盘&#xff0c;道指跌落0.19%&#xff0c;标普500指数跌落0.25%&#xff0c;纳指跌幅为0.10%。 美国ISM7月非制造业PMI下滑 数据面上&#xff0c;美国供应办理协会ISM周四发布的…

掌握好视频翻译软件的使用方法,帮你跨越语言障碍

嘿&#xff0c;翻译小达人们&#xff0c;你知道吗&#xff0c;当你看到一段充满神秘符号的英语视频&#xff0c;脑袋里冒出一大片问号的时候&#xff0c;别慌&#xff01;我们有比手动翻译更妙的解决办法——视频翻译。嗯&#xff0c;这货可不一般&#xff0c;它能帮你解读视频…

锂电设备振动监测:早发现问题,早预防故障

锂电设备在生产过程中的振动问题可能导致设备故障、损坏和生产线停机&#xff0c;对企业产生严重影响。为了确保锂电池生产的稳定性和可靠性&#xff0c;振动监测成为了关键一步。通过引入智能无线温振传感器及其监测分析软件&#xff0c;企业可以早发现问题、早预防故障&#…

[PaddlePaddle] [学习笔记] PaddlePaddle 官方文档 —— 使用Python和NumPy构建神经网络模型

1. 机器学习和深度学习综述 1.1 人工智能、机器学习、深度学习的关系 近些年人工智能、机器学习和深度学习的概念十分火热&#xff0c;但很多从业者却很难说清它们之间的关系&#xff0c;外行人更是雾里看花。在研究深度学习之前&#xff0c;先从三个概念的正本清源开始。概括…

节能延寿:ARM Cortex-M微控制器下的低功耗定时器应用

嵌入式系统的开发在现代科技中发挥着至关重要的作用。它们被广泛应用于从智能家居到工业自动化的各种领域。在本文中,我们将聚焦于使用ARM Cortex-M系列微控制器实现低功耗定时器的应用。我们将详细介绍在嵌入式系统中如何实现低功耗的定时器功能,并附上代码示例。 嵌入式系…

详聊API接口?淘宝API接口在ERP系统中扮演者什么角色?

什么是API&#xff1f; API全称应用程序编程接口&#xff08;Application Programming Interface&#xff09;&#xff0c;是一组用于访问某个软件或硬件的协议、规则和工具集合。电商API就是各大电商平台提供给开发者访问平台数据的接口。目前&#xff0c;主流电商平台如淘宝…

Ubuntu 22.04安装和使用ROS1可行吗

可行。 测试结果 ROS1可以一直使用下去的&#xff0c;这一点不用担心。Ubuntu会一直维护的。 简要介绍 Debian发行版^_^ AI&#xff1a;在Ubuntu 22.04上安装ROS1是可行的&#xff0c;但需要注意ROS1对Ubuntu的支持只到20.04。因此&#xff0c;如果要在22.04上安装ROS1&am…