vuejs 학습노트 v-model v-on v-bind 컴퓨터 vue 삼목 연산자

12843 단어 vuejs
span style="color:#e8de50;">html>
<html lang="en">
<head>
    <meta charset="UTF-8">
    <link rel="stylesheet" href="./css/bootstrap.min.css">
    <title>Titletitle>
head>
<style>
    .complete{
        color: #00a65a;
        text-decoration: line-through;
    }
style>
<body>
<div class="container" id ='app'>
    <div class='row'>
        <div class="panel">
            <div class="panel-heading">
                VUEJS {{ arrCount }}
            div>
            <div class="panel-body">
                <h1>
                    {{ message }}
                h1>
                <input type="text" class="form-control" v-model="message">
                <ul class="list-group">
                    <li class="list-group-item" v-bind:class="{'complete':arrs.complete}"
                        v-for="(arrs,index) in arr">
                            {{ arrs.title }}
                        <button class="btn btn-warning btn-xs pull-right" v-on:click="deleteArr(index)">
                            delete
                        button>
                        <button class="btn btn-xs pull-right" v-bind:class="[arrs.complete ? 'btn-success':'btn-danger']"  v-on:click="onsComplete(arrs)">
                           {{ arrs.complete? 'complete':'off' }}
                        button>
                    li>
                ul>
                <form action="" v-on:submit.prevent = 'addArr(newArr)'>
                    <div class="form-group">
                        <input type="text" class="form-control" v-model="newArr.title" placeholder="title">
                    div>
                    <div class="form-group">
                        <button class="btn btn-success">add arrbutton>
                    div>
                form>
            div>
        div>
    div>
div>
body>
<script src="js/vue.js">script>
<script>
    new Vue({
        el:'#app',
        data:{
            message:'hello word',
            arr:[
                {id:1,title:'trc',age:'20',complete:false}
            ],
            newArr: {id:null,title:'',age:null,complete:false}

        },
        computed:{
            arrCount:function(){
                return this.arr.length
            }
        },
        methods:{
            addArr:function(newArr){
              this.arr.push(newArr);
                this.newArr = {id:null,title:'',age:null};
          },
            deleteArr:function(index){
              console.log(index);
              this.arr.splice(index,1);
            },
            onsComplete:function(arrs){
               arrs.complete = ! arrs.complete;
            }
        }
    });
script>
html>

좋은 웹페이지 즐겨찾기