zoukankan      html  css  js  c++  java
  • 使用vuejs做一个todolist

    在输入框内输入一个list,回车,添加到list列表中,点击列表中的项样式改变

    1、index.html

    <!DOCTYPE html>
    <html>
      <head>
        <meta charset="utf-8">
        <title>my-first-vue-project</title>
      </head>
      <body>
        <div id="app"></div>
        <!-- built files will be auto injected -->
      </body>
    </html>

    2、main.js

    // The Vue build version to load with the `import` command
    // (runtime-only or standalone) has been set in webpack.base.conf with an alias.
    import Vue from 'vue'
    import App from './App'
    
    Vue.config.productionTip = false
    
    /* eslint-disable no-new */
    new Vue({
      el: '#app',
      template: '<App/>',
      components: { App }
    })

    3、App.vue

    <template>
      <div id="app">
        <h1>{{title}}</h1>
        <h1 v-text="title"></h1>
        <h1 v-html="title"></h1>
        <input type="text" v-model="newItem" v-on:keyup.enter="addNew">
        <ul>
            <li v-for="item in items" v-bind:class="{finished:item.isFinished}" v-on:click="toggleFinish(item)">
            {{item.label}}
            </li>
        </ul>
    
      </div>
    </template>
    
    <script>
    
    export default {
      
       data () {
        return {
          title: '<span>?</span>this is a todolist',
          items:[
              {
                label:'coding',
                isFinished:false
      
              },
              {
                label:'walking',
                isFinished:true
      
              }
          ],
          newItem:''
        }
      },
      methods:{
        toggleFinish:function(item){
          // console.log(item);
          item.isFinished=!item.isFinished;
        },
        addNew:function(){
          // this.newItem;
          // console.log(this.newItem);
          this.items.push({
            label:this.newItem,
            isFinished:false
          })
          this.newItem='';
        }
      }
    }
    </script>
    
    <style>
    .finished{
      text-decoration:underline;
    }
    #app {
      font-family: 'Avenir', Helvetica, Arial, sans-serif;
      -webkit-font-smoothing: antialiased;
      -moz-osx-font-smoothing: grayscale;
      text-align: center;
      color: #2c3e50;
      margin-top: 60px;
    }
    </style>
  • 相关阅读:
    php_sphinx安装使用
    获取数据库中所有表名
    总结thinkphp快捷查询getBy、getField、getFieldBy用法及场景
    打印机复印身份证方法
    svn 删除、移动和改名
    MySQL中REGEXP正则表达式使用大全
    高铁在高速运行时的电力是如何提供的?
    2016亚洲大学排名
    Mac下安装HBase及详解
    HBase Mac OSX 安装笔记
  • 原文地址:https://www.cnblogs.com/hongmaju/p/6838529.html
Copyright © 2011-2022 走看看