vuejs学习笔记 v-model v-on v-bind computed vue三目运算符

<!DOCTYPE html>
<html lang="en">
<head>
    <meta charset="UTF-8">
    <link rel="stylesheet" href="./css/bootstrap.min.css">
    <title>Title</title>
</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 arr</button>
                    </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>
  • 0
    点赞
  • 0
    收藏
    觉得还不错? 一键收藏
  • 1
    评论

“相关推荐”对你有帮助么?

  • 非常没帮助
  • 没帮助
  • 一般
  • 有帮助
  • 非常有帮助
提交
评论 1
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值