luguankun

主要用到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>

 

分类:

技术点:

相关文章:

  • 2022-01-03
  • 2022-01-01
  • 2021-12-10
  • 2021-12-18
  • 2021-12-20
  • 2021-07-15
  • 2021-12-21
  • 2021-11-21
猜你喜欢
  • 2021-11-19
  • 2021-11-26
  • 2021-11-27
  • 2021-11-21
  • 2021-11-30
  • 2021-11-27
  • 2021-12-25
相关资源
相似解决方案