码迷,mamicode.com
首页 > 其他好文 > 详细

Vue TodoList 入门 Demo

时间:2018-08-12 18:55:02      阅读:115      评论:0      收藏:0      [点我收藏+]

标签:demo   style   element   html   javascrip   入门   size   lang   add   

// 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

标签:demo   style   element   html   javascrip   入门   size   lang   add   

原文地址:https://www.cnblogs.com/phpcurd/p/9463602.html

(0)
(0)
   
举报
评论 一句话评论(0
登录后才能评论!
© 2014 mamicode.com 版权所有  联系我们:gaon5@hotmail.com
迷上了代码!