zoukankan      html  css  js  c++  java
  • Vue 小练习01

    • 有红, 黄, 蓝三个按钮, 以及一个200X200px的矩形box, 点击不同的按钮, box的颜色会被切换为指定的颜色
    <!DOCTYPE html>
    <html lang="en">
    <head>
       <meta charset="UTF-8">
       <title>Title</title>
    
    </head>
    <body>
    <div id="d1">
    
       <p :style="myStyle"></p>
    
       <button :style="{backgroundColor: bgc1}" @click="f1">按钮一</button>
       <button :style="{backgroundColor: bgc2}" @click="f2">按钮二</button>
       <button :style="{backgroundColor: bgc3}" @click="f3">按钮三</button>
    </div>
    
    <script src="vue/vue.js"></script>
    <script>
       new Vue({
           el: '#d1',
           data: {
               bgc1: 'red',
               bgc2: 'yellow',
               bgc3: 'blue',
               myStyle: {
                    '200px',
                   height: '200px',
                   backgroundColor: 'black'
               }
           },
           methods: {
               f1() {
                   this.myStyle.backgroundColor = this.bgc1
               },
               f2() {
                   this.myStyle.backgroundColor = this.bgc2
               },
               f3() {
                   this.myStyle.backgroundColor = this.bgc3
               },
           }
       })
    </script>
    
    
    </body>
    </html>
    
    • 一个200X200px的矩形box, 点击box本身, 记录点击次数, 1次box变为粉色, 2次变为绿, 3次变为蓝色, 4次重新回到粉色, 依次类推
    <!DOCTYPE html>
    <html lang="en">
    <head>
        <meta charset="UTF-8">
        <title>Title</title>
    
    </head>
    <body>
    <div id="d1">
    
        <p :style="myStyle" @click="f1">{{ counter }}</p>
    
    
    </div>
    
    <script src="vue/vue.js"></script>
    <script>
        new Vue({
            el: '#d1',
            data: {
                counter: 0,
                bgc1: 'pink',
                bgc2: 'green',
                bgc3: 'cyan',
                myStyle: {
                     '200px',
                    height: '200px',
                    backgroundColor: 'black'
                }
            },
            methods: {
                f1() {
                    this.counter += 1;
                    if (this.counter % 3 === 1) {
                        this.myStyle.backgroundColor = this.bgc1
                    }else if (this.counter % 3 === 2) {
                        this.myStyle.backgroundColor = this.bgc2
                    }else {
                        this.myStyle.backgroundColor = this.bgc3
                    }
                }
            }
        })
    </script>
    
    
    </body>
    </html>
    
  • 相关阅读:
    第三章 运算符与表达式
    python 第二章 对象与类型
    线段树区间染色+注意事项
    ACM-ICPC北京赛区2018重现赛 A题
    删除元组
    修改元组
    访问元组
    Python 元组
    Python List sort()方法
    hdu4501——小明系列故事——买年货(多维背包)
  • 原文地址:https://www.cnblogs.com/bigb/p/12052272.html
Copyright © 2011-2022 走看看