zoukankan      html  css  js  c++  java
  • 初识Vue,简单的todolist

    vue开发源码:https://vuejs.org/js/vue.js

    todolist代码:

    <!DOCTYPE html>
    <html lang="en">
    <head>
      <meta charset="UTF-8">
      <title>vue入门</title>
      <script src="vue.js" type="text/javascript" charset="utf-8"></script>
    </head>
    <body>
      <div id="app">
        <input v-model="inputValue" type="text" name="">
        <button @click="submit">提交</button>
       
        <ul>
          <todo-item 
            v-for="(item, index) in list" 
            :key="index" 
            :content="item" 
            :index="index" 
            @delete="handleDelete"
            @update="handleUpdate"
            >
          </todo-item>
        </ul>
        <input v-model="updateValue" type="text" name="">
        <button @click="update">确定</button>
      </div>
    </body>
    <script type="text/javascript">
    
      Vue.component("todo-item", {
        props:["content", "index"],
        template:'<li>{{content}} <button @click="handleClick">remove</button><button @click="handleUp">update</button></li>',
        methods:{
          handleClick:function() {
            this.$emit('delete', this.index)
          },
          handleUp:function() {
            this.$emit('update', this.index)
          }
        }
      })
    
      new Vue({
        el:"#app",
        data: {
          inputValue : '',
          updateValue : '',
          in:'',
          list:[]
        },
        methods: {
          submit:function() {
            if(this.inputValue.trim() !== "") {
              this.list.push(this.inputValue);
            }
              this.inputValue = ''
          },
          handleDelete: function(index) {
            this.list.splice(index, 1);
          },
          handleUpdate: function(index) {
            this.updateValue = this.list[index]
            this.in = index;
          },
          update: function() {
            console.log(this.in)
            this.list.splice(this.in, 1, this.updateValue);
            this.updateValue = ''
          }
        }
      })
    </script>
    </html>
    

      重点:子组件与父组件的值传递

  • 相关阅读:
    Protected和Default的区别
    将数组中负数放在正数前面
    java.io包和杯子测楼
    hadoop基础
    极限编程和JUnit
    接口和抽象类
    C# 中窗口AutoScaleMode属性
    计算机的自启动管理
    labview中的移位寄存器、循环隧道,自动索引隧道的区别
    发现C#winform编程中不常用的控件(一)<FlowLayoutPanel控件><拆分器控件Splitcontainer >
  • 原文地址:https://www.cnblogs.com/detanx/p/vueTodolist.html
Copyright © 2011-2022 走看看