zoukankan      html  css  js  c++  java
  • vuejs小例子之记事本

    <html>
    
    <head>
      <script src="https://cdn.jsdelivr.net/npm/vue/dist/vue.js"></script>
      <style>
        #app {
          margin: 0px auto;
           500px;
          border: 1px solid blue;
          height: 500px;
        }
    
        .title {
          line-height: 50px;
          text-align: center;
          height: 50px;
          font-weight: 20px;
          font-size: 36px;
          background: coral;
        }
    
        .inp {
          outline-style: none;
          border: 0px solid #ccc;
           330px;
          font-size: 15px;
          padding: 3px 3px;
          font-family: "Microsoft soft";
        }
    
        input:focus {
          border-color: #66afe9;
          outline: 0;
          -webkit-box-shadow: inset 0 1px 1px rgba(0, 0, 0, .075), 0 0 8px rgba(102, 175, 233, .6);
          box-shadow: inset 0 1px 1px rgba(0, 0, 0, .075), 0 0 8px rgba(102, 175, 233, .6)
        }
    
        ul,
        li {
          padding: 0;
          margin: 0;
          list-style: none;
        }
    
        .li-div {
          text-align: center;
          border: 3px solid white;
        }
      </style>
    </head>
    
    <body>
      <div id="app">
        <div class="title">
          记事本
        </div>
        <hr>
        <div>
          <span>
            <p style="color: chartreuse">请输入内容:
              <input type="text" placeholder="按回车保存" class="inp" v-model="tmp" @keyup.enter="add">
            </p>
          </span>
        </div>
        <hr>
        <div class="content">
          <ul>
            <li v-for="(item, index) in message">
              <div class="li-div">
                <span>{{index}}</span>
                <label>{{item}}</label>
                <button @click="remove(index)">删除</button>
              </div>
            </li>
          </ul>
        </div>
        <hr>
        <div v-show="message.length>0">
          <div style="float: left;">
            当前记事本记录数:{{message.length}}
          </div>
          <div style="float: right;;">
            <button @click="clear">清空</button>
          </div>
        </div>
      </div>
      <script>
        var app = new Vue({
          el: '#app',
          data: {
            tmp: "",
            message: ['今天好开心', '今天超级棒', '今天美美哒'],
          },
          methods: {
            add: function () {
              if (this.tmp == null || this.tmp == "") {
                alert("输入不能为空");
              } else {
                this.message.push(this.tmp);
              }
            },
            remove: function (ind) {
              var flag = confirm("是否要删除删除" + ind);
              if (flag == true) {
                this.message.splice(ind, 1);
              }
            },
            clear: function () {
              this.message = [];
            },
          },
        })
      </script>
    </body>
    
    </html>

    效果:

    在输入框中输入内容并回车:

    删除编号为1的数据:

    清空记事本:

    说明:综合使用了vue.js的多个指令,包括:

    使用v-for来显示列表数据。

    使用v-on来进行删除和清空操作。

    使用v-on进行新增操作,具体是keyup.enter事件。

    使用v-model将文本框中的数据和vue-data中的数据进行绑定。

    使用v-show根据条件进行显示记录数和清空按钮。

  • 相关阅读:
    iPhone 3开发基础教程这本书怎么样
    好久没有用过VS6.0了。
    关于UNIX环境高级编程(第2版)——图灵计算机科学丛书的读后感
    强烈推荐C++ Primer 习题解答(第4版)
    C标准库这本书怎么样
    关于C语言程序设计:现代方法(第2版)的读后感
    强烈推荐JavaScript DOM高级程序设计
    强烈推荐深入浅出Ext JS(第2版)(附光盘)
    关于PHP与MySQL程序设计(第3版)的读后感
    强烈推荐NET设计规范:约定、惯用法与模式(第2版)(附光盘)
  • 原文地址:https://www.cnblogs.com/xiximayou/p/12321581.html
Copyright © 2011-2022 走看看