作业一:有红黄蓝三个按钮,以及一个200*200矩形box,点击不同按钮,box的颜色会被切换为指定的颜色

<!DOCTYPE html>
<html lang="en">
<head>
    <meta charset="UTF-8">
    <title></title>
    <script src="https://cdn.bootcss.com/jquery/3.4.1/jquery.min.js"></script>
</head>
<body>
<div id="app">

    <div :style="div_style"></div>
    <div>
        <button v-on:click="changeColor('red')">{{ red }}</button>
        <button v-on:click="changeColor('yellow')">{{ yellow }}</button>
        <button v-on:click="changeColor('blue')">{{ blue }}</button>
    </div>
</div>

</body>
<script src="Vue/vue.js"></script>
<script>
    var app = new Vue({
        el: '#app',
        data: {
            div_style: {
                width: "200px",
                height: "200px",
                backgroundColor: "black"
            },
            red: '点击变红',
            yellow: '点击变黄',
            blue: '点击变蓝',
        },
        methods: {
            changeColor(c) {
                this.div_style.backgroundColor = c;
            }
        }
    })
</script>
</html>

作业二:有一个200*200的矩形wrap框,点击wrap本身,记录点击次数,如果是1次wrap为pink色,2次wrap为green,3次warp为cyan色,4次重新回到pink色,一次类推。


<!DOCTYPE html><html lang="en"><head>    <meta charset="UTF-8">    <title>Title</title>    <style>        .wrap{            width: 200px;            height: 200px;            color: white;            font: bold 50px/200px 'STSong';            text-align: center;            user-select: none;        }    </style></head><body><div id="app">    <div class="wrap" @click="actionFn" :style="{backgroundColor:bgColor}">{{content}}</div></div></body><script src="js/vue.js"></script><script>    new Vue({        el:'#app',        data:{            content:0,            bgColor:'black',            colorArr:['cyan','pink','green'],        },        methods:{            actionFn(){                this.content ++;                this.bgColor=this.colorArr[this.content % 3]            }        }    })

</script>

</html>

作业三:

<!DOCTYPE html>
<html lang="en">
<head>
    <meta charset="UTF-8">
    <title>Title</title>
    <style>
        .wrap {
            border: 3px solid black;
            width: 200px;
            height: 200px;
            border-radius: 50%;
            overflow: hidden;
            margin: 50px auto 0;
            position: relative;
        }

        .red, .green {
            width: 100px;
            height: 200px;
            position: absolute;
        }

        .red {
            background-color: red;
        }

        .green {
            background-color: green;
        }

        .l {
            width: 100px;
            height: 200px;
            left: 0;
        }

        .t {
            width: 200px;
            height: 100px;
            top: 0;
        }

        .r {
            width: 100px;
            height: 200px;
            right: 0;
        }

        .b {
            width: 200px;
            height: 100px;
            bottom: 0;
        }
    </style>
</head>
<body>
<div id="app">
    <div class="wrap" @click="actionFn">
        <div class="red" :class="red_class"></div>
        <div class="green" :class="green_class"></div>
        <div></div>
    </div>
</div>
</body>
<script src="js/vue.js"></script>
<script>
    new Vue({
        el: '#app',
        data: {
            count: 0,
            red_class: 'l',
            green_class: 'r',
            red_attr: ['l', 't', 'r', 'b'],
            green_attr: ['r', 'b', 'l', 't'],
        },
        methods: {
            actionFn() {
                this.count ++;
                this.red_class = this.red_attr[this.count % 4];
                this.green_class = this.green_attr[this.count % 4];
            }
        }
    })

</script>
</html>

第三题的第二问:

<!DOCTYPE html>
<html lang="en">
<head>
    <meta charset="UTF-8">
    <title>Title</title>
</head>
<body>

<div id="app">
    <form action="" style="margin: 20px;">
        <p @click="tag" :style="{width: w,height: h, background: bgc, borderRadius:rad}"></p>
    </form>
</div>

</body>
<script src="Vue/vue.js"></script>
<script>
    let num = 0;
    let app = new Vue({
        el:'#app',
        data:{
            h: '200px',
            w: '200px',
            bgc: 'linear-gradient(to top, red 50%, green 50%)',  //实现页面的过度(颜色)
            rad: '50%'
            },
        methods:{
            tag () {
                num += 1;
                if (num==1){
                    this.bgc = 'linear-gradient(to top, red 50%, green 50%)' // 控制方向
                }else {if (num==2){
                    this.bgc = 'linear-gradient(to left, red 50%, green 50%)'
                }else {if (num==3) {
                    this.bgc = 'linear-gradient(to bottom,red  50%, green 50%)'
                }else {
                    this.bgc = 'linear-gradient(to right, red 50%, green 50%)';
                    num = 0
                }
                }}
            }
        }
    });
    function funcTest(){
    window.setInterval(app.tag,500);  // 按照指定的周期(以毫秒计)来调用函数
}
    window.onload = funcTest;  // 页面加载完直接调用 该方法
</script>
</html>

VUE-练习的更多相关文章

  1. Vue.js 和 MVVM 小细节

    MVVM 是Model-View-ViewModel 的缩写,它是一种基于前端开发的架构模式,其核心是提供对View 和 ViewModel 的双向数据绑定,这使得ViewModel 的状态改变可以自 ...

  2. wepack+sass+vue 入门教程(三)

    十一.安装sass文件转换为css需要的相关依赖包 npm install --save-dev sass-loader style-loader css-loader loader的作用是辅助web ...

  3. wepack+sass+vue 入门教程(二)

    六.新建webpack配置文件 webpack.config.js 文件整体框架内容如下,后续会详细说明每个配置项的配置 webpack.config.js直接放在项目demo目录下 module.e ...

  4. wepack+sass+vue 入门教程(一)

    一.安装node.js node.js是基础,必须先安装.而且最新版的node.js,已经集成了npm. 下载地址 node安装,一路按默认即可. 二.全局安装webpack npm install ...

  5. Vue + Webpack + Vue-loader 系列教程(2)相关配置篇

    原文地址:https://lvyongbo.gitbooks.io/vue-loader/content/ 使用预处理器 在 Webpack 中,所有的预处理器需要和一个相应的加载器一同使用.vue- ...

  6. Vue + Webpack + Vue-loader 系列教程(1)功能介绍篇

    原文地址:https://lvyongbo.gitbooks.io/vue-loader/content/ Vue-loader 是什么? vue-loader 是一个加载器,能把如下格式的 Vue ...

  7. 关于Vue.js 2.0 的 Vuex 2.0,你需要更新的知识库

    应用结构 实际上,Vuex 在怎么组织你的代码结构上面没有任何限制,相反,它强制规定了一系列高级的原则: 应用级的状态集中放在 store 中. 改变状态的唯一方式是提交mutations,这是个同步 ...

  8. Vue.js 2.0 和 React、Augular等其他框架的全方位对比

    引言 这个页面无疑是最难编写的,但也是非常重要的.或许你遇到了一些问题并且先前用其他的框架解决了.来这里的目的是看看Vue是否有更好的解决方案.那么你就来对了. 客观来说,作为核心团队成员,显然我们会 ...

  9. 窥探Vue.js 2.0 - Virtual DOM到底是个什么鬼?

    引言 你可能听说在Vue.js 2.0已经发布,并且在其中新添加如了一些新功能.其中一个功能就是"Virtual DOM". Virtual DOM是什么 在之前,React和Em ...

  10. 初探Vue

    Vue.js(读音/vju:/,类似于view),是近来比较火的前端框架,但一直没有怎么具体了解.实现过,就知道个啥的MVVM啦,数据驱动啦,等这些关于Vue的虚概念. 由于最近,小生在公司中,负责开 ...

随机推荐

  1. [bzoj3357][Usaco2004]等差数列_动态规划_贪心

    [Usaco2004]等差数列 题目大意:约翰发现奶牛经常排成等差数列的号码.他看到五头牛排成这样的序号:“1,4,3,5,7”很容易看出“1,3,5,7”是等差数列.给出N(1≤N≤2000)数字A ...

  2. Centos7 安装部署 Airflow

    本人在centos7 的环境下部署,怎么在centos7 下配置静态 IP 关闭防火墙 以及安装jdk在这里不多赘述, centos7 配置静态ip可以参考:https://www.cnblogs.c ...

  3. python报错及处理 -- 不断总结

    ModuleNotFoundError: No module named 'PIL' 解决方法: 运行命令:pip install Pillow IndentationError: expected ...

  4. 啃掉Hadoop系列笔记(03)-Hadoop运行模式之本地模式

    Hadoop的本地模式为Hadoop的默认模式,不需要启用单独进程,直接可以运行,测试和开发时使用. 在<啃掉Hadoop系列笔记(02)-Hadoop运行环境搭建>中若环境搭建成功,则直 ...

  5. Hadoop集群搭建-05安装配置YARN

    Hadoop集群搭建-04安装配置HDFS  Hadoop集群搭建-03编译安装hadoop Hadoop集群搭建-02安装配置Zookeeper Hadoop集群搭建-01前期准备 先保证集群5台虚 ...

  6. 解决mac启动springboot项目很慢的问题

    1.打开终端输入: hostname 查看电脑名称 2.输入命令修改hosts文件 sudo vi /etc/hosts 3. 在127.0.0.1和::1后边分别增加你的电脑名称 127.0.0.1 ...

  7. spark的安装步骤

    官网:http://spark.apache.org/downloads.html 安装:tar -zxvf spark-2.4.3-bin-hadoop2.7.tgz#配置环境变量(vim ~/.b ...

  8. 03docker镜像

    docker的镜像操作 Union文件系统是Docker镜像的基础. UnionFS(联合文件系统):Union文件系统是一种分层,轻量级并且高性能的文件系统.它支持对文件系统的修改作为一次提交来一层 ...

  9. MyBatis-plus 新增实例,主键ID从很大的数字开始

    mybatis-plus是mybatis增强版,用mybatis-plus可以省去很多DAO层代码和数据库操作语句的编写.但是需要我们配置好条件. 情景: 向数据库新增一条实例,我们要调用 inser ...

  10. 深入理解hadoop数据倾斜

    深入理解hadoop之数据倾斜 1.什么是数据倾斜 我们在用map /reduce程序执行时,有时候会发现reduce节点大部分执行完毕,但是有一个或者几个reduce节点运行很慢,导致整个程序的处理 ...