todoList

结合之前 Vuejs 基础与语法

  • 使用 v-model 双向绑定 input 输入内容与数据 data
  • 使用 @click 和 methods 关联事件
  • 使用 v-for 进行数据循环展示
<!DOCTYPE html>
<html lang="en">
<head>
  <meta charset="UTF-8">
  <title>TodoList</title>
  <script src="./vue.js"></script>
</head>
<body>
  <div id="root">
    <div>
      <input v-model="inputValue"/>
      <button @click="handleSubmit">提交</button>
    </div>
    <ul>
      <li v-for="(item,index) of list" :key="index">
        {{item}}
      </li>
    </ul>
  </div>

  <script>
    new Vue({
      el: "#root",
      data: {
        inputValue: '',
        list: []
      },
      methods: {
        handleSubmit: function(){
          this.list.push(this.inputValue)
          this.inputValue = ''
        }
      }
    })
  </script>
</body>
</html>
View Code

相关文章:

  • 2022-12-23
  • 2022-12-23
  • 2021-11-30
  • 2022-12-23
  • 2022-12-23
  • 2021-11-04
  • 2022-12-23
猜你喜欢
  • 2022-12-23
  • 2022-12-23
  • 2021-05-05
  • 2021-06-23
  • 2022-12-23
  • 2022-12-23
相关资源
相似解决方案