利用js实现vue创建事项清单表单代码



19 73 25



特效描述:利用js实现 vue 创建事项 清单表单代码,利用js实现vue创建事项清单表单代码

代码结构

1. 引入CSS

<link href="https://fonts.googleapis.com/css?family=Quicksand" rel="stylesheet">
<link href="https://fonts.googleapis.com/icon?family=Material+Icons" rel="stylesheet">

2. 引入JS

<script src="js/vue.min.js"></script>

3. HTML代码

<main id="todolist">
  <h1>
   	事项清单
    <span>把事情完成,每次一个项目。</span>
  </h1>
  <template v-if="todo.length">
    <ul>
      <li v-for="item in todoByStatus" stagger="5000" v-bind:class="item.done ? 'done' : ''">
        <span class="label">{{item.label}}</span>
        <div class="actions">
          <button class="btn-picto" type="button" v-on:click="markAsDoneOrUndone(item)" v-bind:aria-label="item.done ? 'Undone' : 'Done'" v-bind:title="item.done ? 'Undone' : 'Done'">
            <i aria-hidden="true" class="material-icons">{{ item.done ? 'check_box' : 'check_box_outline_blank' }}</i>
          </button>
          <button class="btn-picto" type="button" v-on:click="deleteItemFromList(item)" aria-label="Delete" title="Delete">
            <i aria-hidden="true" class="material-icons">删除</i>
          </button>
        </div>
      </li>
    </ul>
    <togglebutton 
                  label="在最后移动完成的项目?"
                  name="todosort"
                  v-on:clicked="clickontoogle" />
  </template>
  <p v-else class="emptylist"> 你的待办事项列表是空的。 </p>
  <form name="newform" v-on:submit.prevent="addItem">
    <label for="newitem">添加到待办事项列表</label>
    <input type="text" name="newitem" id="newitem" v-model="newitem">
    <button type="submit">添加项目</button>
  </form>
</main>
<script>
Vue.component('togglebutton', {
  props: ['label', 'name'],
  template: `<div class="togglebutton-wrapper" v-bind:class="isactive ? 'togglebutton-checked' : ''">
      <label v-bind:for="name">
        <span class="togglebutton-label">{{ label }}</span>
        <span class="tooglebutton-box"></span>
      </label>
      <input v-bind:id="name" type="checkbox" v-bind:name="name" v-model="isactive" v-on:change="onToogle">
  </div>`,
  model: {
    prop: 'checked',
    event: 'change'
  },
  data: function() {
    return {
      isactive:false
    }
  },
  methods: {
    onToogle: function() {
       this.$emit('clicked', this.isactive)
    }
  }
});
var todolist = new Vue({
  el: '#todolist',
  data: {
    newitem:'',
    sortByStatus:false,
    todo: [
      { label: "Learn VueJs", done: true },
      { label: "Code a todo list", done: false },
      { label: "Learn something else", done: false }
    ]
  },
  methods: {
    addItem: function() {
      this.todo.push({label: this.newitem, done: false});
      this.newitem = '';
    },
    markAsDoneOrUndone: function(item) {
      item.done = !item.done;
    },
    deleteItemFromList: function(item) {
      let index = this.todo.indexOf(item)
      this.todo.splice(index, 1);
    },
    clickontoogle: function(active) {
      this.sortByStatus = active;
    }
  },
  computed: {
    todoByStatus: function() {
      if(!this.sortByStatus) {
        return this.todo;
      }
      var sortedArray = []
      var doneArray = this.todo.filter(function(item) { return item.done; });
      var notDoneArray = this.todo.filter(function(item) { return !item.done; });
      sortedArray = [...notDoneArray, ...doneArray];
      return sortedArray;
    }
  }
});
</script>
<div style="text-align:center;margin:50px 0; font:normal 14px/24px 'MicroSoft YaHei';">
</div>



用户评论
大牛,别默默的看了,快登录帮我点评一下吧!:)      登录 | 注册


热门标签: 加载动画 h5弹窗动画 html5弹窗动画 h5动画 h5背景动画 h5场景动画 h53D动画 h5界面动画 html5动画 h5按钮动画 html5按钮动画 h5线条动画 html5线条动画

×
×

注册

官方QQ群

扫描上面二维码加微信群

官方QQ群

jQuery/js讨论群
群号:642649996
Css3+Html5讨论群
群号:322131262

加群请备注:从官网了解到