• 使用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>
  • 相关阅读:
    distributed caching for .net applications
    Linux_18/ mysql
    找到一本不错的Linux电子书,附《Linux就该这么学》章节目录。
    LinuxProbe/ 疑问ABC
    Linux_15/ autofs, DNS
    Linux_14/ SAMBA, NFS
    Linux_13/ 虚拟网站主机功能,Vsftpd
    Linux_12/ Apache, SELinux
    Linux_11/ firewalld-config, SSH, bounding
    Linux_10/ iptables & firewalld
  • 原文地址:https://www.cnblogs.com/hongmaju/p/6838529.html
Copyright © 2020-2023  润新知