• 用vue实现输入搜索功能


    主要用到js的filter方法和match方法和vue的computed属性实现

    <template>
      <div id="app">
        <input type="text" v-model="searchVal">
          <div class="ctn"  v-for="(item,i) in search">
            <h3>{{item.title}}</h3>
            <p>{{item.body}}</p>
          </div>
       </div>
    </template>
    
    <script>
    export default {
      name: 'App',
      data(){
        return {
          searchVal:"",
          blog:[]
        }
      },
      created(){
        this.$axios.get("http://jsonplaceholder.typicode.com/posts").then(res=>{
          console.log(res);
          this.blog = res.data;
        });
      },
      computed:{
        search(){
          var item = this.blog.filter(ele=>{
            if(ele.title.match(this.searchVal)){
              return ele;
            }
          })
           return item;
        }
      }
    }
    </script>
  • 相关阅读:
    2016/09/18
    2016/09/16
    2016/09/15
    2016/09/14
    2016/09/13
    2016/09/12
    2016/09/03
    2016/09/02
    HDU1850 Being a Good Boy in Spring Festival(NIM)
    POJ3070 Fibonacci(矩阵快速幂)
  • 原文地址:https://www.cnblogs.com/luguankun/p/10832027.html
Copyright © 2020-2023  润新知