欧美bbbwbbbw肥妇,免费乱码人妻系列日韩,一级黄片

vue2 前端搜索實(shí)現(xiàn)示例

 更新時間:2018年02月26日 14:59:29   作者:yue朔  
本篇文章主要介紹了vue2 前端搜索實(shí)現(xiàn)示例,小編覺得挺不錯的,現(xiàn)在分享給大家,也給大家做個參考。一起跟隨小編過來看看吧

項目數(shù)據(jù)少的時候,搜索這樣的小事情就要交給咱們前端來做了,重要聲明,適用于小項目?。。。?!

其實(shí)原理很簡單,小demo是做搜索市區(qū)名稱或者按照排名搜索。

<div>
   <input type="text" v-model="name" placeholder="點(diǎn)擊搜索按鈕篩選" />
   <input type="button" @click="search" />
</div>
<table>
     <tbody>
       <tr v-for="item in listt0">
        <td>
        <a v-text="item.sort"></a>
        </td>
        <td>
        <a v-text="item.City"></a>
        </td>
        <td>
          <a :style="{'color':item.sort<=10?'#f2972e':''}" v-cloak>{{item.Data | two}}</a>
         </td>
          <td><span v-text="item.Good"></span></td>
          </tr>
        </tbody>
</table>

頁面布局成功之后,就是要做js配置了,首先是data初始化。

data:{
  list0:[],//原始
  listt0:[],//處理過的
  name:'',//搜索框內(nèi)容
}, 

接下來獲取后臺數(shù)據(jù),后臺數(shù)據(jù)必須是一次性傳遞給前端,原因你懂的。

created:function(){
  //這獲取數(shù)據(jù)且list0以及l(fā)istt0都為獲取到的數(shù)據(jù)
},

搜索的實(shí)現(xiàn),判斷如果是數(shù)字就按照sort搜索,不是數(shù)字則按照city搜索。一個簡單的搜索就完成了。

        methods:{
           search:function(){//搜索
             var _this=this;
             var tab=this['list0'];
             if(this.name){                   
              _this['listt0']=[];           
               if(!isNaN(parseInt(_this.name))) {
                for(i in tab) {
                  if(tab[i].sort == parseInt(_this.name)) {
                    _this['listt0'].push(tab[i]);
                  };
                };
              } else {
                for(i in tab) {
                  if(tab[i].City.indexOf(_this.name) >= 0) {
                    _this['listt0'].push(tab[i]);
                  };
                };
              };
             }else{
               alert('請輸入篩選條件!')
             };
           }
        },  

小知識點(diǎn):

  1. :style="{'color':item.sort<=10?'#f2972e':''}" :style設(shè)置前10名的文字顏色。

  2. !isNaN(parseInt(_this.name)) 判斷輸入的是數(shù)字還是文字,如果有數(shù)字就會按照數(shù)字搜索。

    3.過濾器two

     filters: {//保留兩位小數(shù)點(diǎn)
          two : function(value){
            if (!value) { return ''};
            return value.toFixed(2);
          }
        }

以上就是本文的全部內(nèi)容,希望對大家的學(xué)習(xí)有所幫助,也希望大家多多支持腳本之家。

相關(guān)文章

最新評論