Vue TodoList 入门 Demo

Posted phpcurd

tags:

篇首语:本文由小常识网(cha138.com)小编为大家整理,主要介绍了Vue TodoList 入门 Demo相关的知识,希望对你有一定的参考价值。

// TodoList 实例

 

<!DOCTYPE html>
<html lang="en">
<head>
    <meta charset="UTF-8">
    <title>This is todo List</title>
    <style type="text/css">
        .isFinshed{font-size: 20px; font-weight: 800; color: red;}
    </style>
</head>
<body>
<div id="app">
    <input type="text" v-model="message" @keyup.enter="itemsPush">
    <ol>
        <todo-item v-for="(item, index) in items" :key="index" :content="item.label" :index="index" @delete="todoListDelete" :class="{isFinshed: item.isFinshed}"></todo-item>
    </ol>
</div>
</body>
<script src="https://cdn.bootcss.com/vue/2.4.2/vue.min.js"></script>
<script type="text/javascript">
    Vue.component(‘todo-item‘, {
        props: [‘content‘, ‘index‘],
        template: ‘<li @click="handleClick">{{ content }}</li>‘,
        methods: {
            handleClick: function () {
                this.$emit(‘delete‘, this.index)
            }
        },
    })
// Vue Instance
    let app = new Vue({
        el: ‘#app‘,
        data: {
            message: ‘‘,
            items: [
                {
                    label: ‘makeing‘,
                    isFinshed: true,
                },
                {
                    label: ‘coding‘,
                    isFinshed: true,
                },
                {
                    label: ‘walking‘,
                    isFinshed: false,
                },
            ],
        },
        methods: {
// delete element or change element Sytle todoListDelete: function (index) { this.items.splice(index, 1); // this.items[index].isFinshed = ! this.items[index].isFinshed; }, // add new element itemsPush: function () { this.items.push({ label: this.message, isFinshed: false, }); this.message = ‘‘; }, }, }) </script> </html>

  

以上是关于Vue TodoList 入门 Demo的主要内容,如果未能解决你的问题,请参考以下文章

1-2 Mobx 入门实践之TodoList(官方Demo)

04慕课网《vue.js2.5入门》——Vue-cli开发todolist

Vuejs入门todolist项目解析

基于vue的todolist案例

初识Vue,简单的todolist

微信小程序的简单应用-Todolist