过滤

2018-04-01  本文已影响0人  知识分享share
<!DOCTYPE html>
<html>
<head>
    <meta charset="UTF-8">
    <title>vue</title>
    <script src="https://cdn.jsdelivr.net/npm/vue@2.5.16/dist/vue.js">
    </script>
    <style>
    </style>
</head>
<body>
<h1>多个实例</h1>
    <div id="app-one">

        <input  v-model="text" type="text">
        <!-- <button v-on:click="handleClick()">add</button> -->
        <ul>
                   <li v-for="(data,index) in processDatalis" :key="data">
                    {{data}}</li>
                   
        </ul>       
    </div>
</body>
</html>
<script>
  var vm = new Vue({
        el: "#app-one",
        data:{
            text:"",
            datalist:["sdfs","wewef","vdfvwe","123","53454"]
        },
        methods:{
            handleClick(){
                this.datalist.push(this.text);
            }
        },
        computed:{
            processDatalis(){
                return this.datalist.filter((item,index)=>item.indexOf(this.text)>-1);
            }
        }
    });
</script>

上一篇 下一篇

猜你喜欢

热点阅读