• vue语法小练习


    实现功能:新增/删除 学生

    <html>
     
      <head>
        <script src="https://cdn.staticfile.org/vue/2.2.2/vue.min.js"></script>
      </head>
      
      <body>
        <div id="app">
          <fieldset>
            <legend>学生信息新增</legend>
            <div>
              <span>姓名</span>
              <input type="text" v-model="newStudent.name" placeholder="please input your name"></div>
            <div>
              <span>年龄</span>
              <input type="text" v-model="newStudent.age" placeholder="please input your age"></div>
            <div>
              <span>性别</span>
              <select v-model="newStudent.sex">
                <option value="男"></option>
                <option value="女"></option></select>
            </div>
            <button @click="insert()">添加</button></fieldset>
          <table>
            <thead>
              <tr>
                <th>姓名</th>
                <th>年龄</th>
                <th>性别</th>
                <th>操作</th></tr>
            </thead>
            <tbody>
              <tr v-for="(st, index) in students">
                <td>{{st.name}}</td>
                <td>{{st.age}}</td>
                <td>{{st.sex}}</td>
                <td>
                  <button @click="del(index)">Delete</button></td>
                <td></td>
              </tr>
            </tbody>
          </table>
        </div>
        <script>new Vue({
            el: '#app',
            data: {
              students: [{
                name: '张三',
                age: 12,
                sex: ''
              },
              {
                name: '李四',
                age: 14,
                sex: ''
              },
              {
                name: '王五',
                age: 15,
                sex: ''
              },
              ],
              newStudent: {
                name: '',
                age: 0,
                sex: ''
              }
            },
            methods: {
              insert() {
                this.students.unshift(this.newStudent)
                //重置表单数据
                this.newStudent = {
                  name: '',
                  age: 0,
                  sex: ''
                }
              },
              del(index) {
                this.students.shift(index, 1)
              }
            }
          })</script>
      </body>
    
    </html>
  • 相关阅读:
    Spring创建对象的方法
    Spring学习笔记1
    WIN7系统TortoiseSVN右键没有菜单解决办法
    TotoiseSVN的基本使用方法
    sql语句中where 1=1和 0=1 的作用
    windows批处理命令教程
    Mysql之B树索引
    Mysql与索引有关的树的概念
    Mysql索引简介
    Mysql之explain详解
  • 原文地址:https://www.cnblogs.com/dannyyao/p/10200956.html
Copyright © 2020-2023  润新知