最新国产好看的视频,伊人天堂AV在线,国产Aaaaaa视频,蜜臀视频在线观看一区,人妻av色图,密臀久久久精品影片,青青视频免费观看毛片,久草在线观看视,国产三级精品色情在线

Vue實(shí)現(xiàn)搜索 和新聞列表功能簡單范例

 更新時(shí)間:2018年03月16日 10:07:50   作者:東邊的小山  
本文通過實(shí)例代碼給大家介紹了Vue實(shí)現(xiàn)搜索 和新聞列表功能簡單范例,非常不錯(cuò),具有參考借鑒價(jià)值,感興趣的朋友一起看看吧

效果圖如下所示:


<html xmlns="http://www.w3.org/1999/xhtml">
<head>
  <title>無標(biāo)題頁</title>
   <meta name="apple-mobile-web-app-capable" content="yes">
<meta name="apple-mobile-web-app-status-bar-style" content="black">
<meta name="format-detection" content="telephone=no">
<meta name="format-detection" content="email=no">
<meta name="viewport" content="width=device-width,initial-scale=1,maximum-scale=1,minimum-scale=1,user-scalable=0">
<script src="/style/js/vue.min.js" type="text/javascript"></script>
<script src="https://cdnjs.cloudflare.com/ajax/libs/vue-resource/0.1.17/vue-resource.js"></script>
 <style>
   .box {
    width: 900px;
    height: auto;
    overflow: hidden;
    margin: 30px auto;
   }
   .left {
    height: 150px;
    width: 185px;
    padding: 5px;
    display: inline-block;
    border: 1px solid black;
   }
   .left input {
    padding: 2px;
    margin-top: 10px;
   }
   .right {
    width: 600px;
    height: auto;
    display: inline-block;
    margin-left: 30px;
    vertical-align: top;
   }
   .right table {
    border-collapse: collapse;
    width: 580px;
   }
   .right table th {
    background-color: green;
    padding: 5px;
    text-align: center;
    border: 1px solid black;
    color: #FFFFFF;
   }
   .right table tr {
    text-align: center;
   }
   .right table td {
    border: 1px solid black;
   }
  </style>
</head>
<body>
<div id="app">
   <div class="box">
    <div class="left">
     <input type="text" placeholder="輸入編號" v-model="id" />
     <input type="text" placeholder="輸入名稱" v-model="name" /><br />
     <input type="button" value="添加數(shù)據(jù)" @click="add" />
     <input type="text" placeholder="搜索數(shù)據(jù)" v-model="search" />
    </div>
    <div class="right">
     <table>
      <tr>
       <th>編號</th>
       <th>品牌名稱</th>
       <th>創(chuàng)建時(shí)間</th>
       <th>操作</th>
      </tr>
      <tr v-for="item in searchData">
       <td>{{item.id}}</td>
       <td>{{item.name}}</td>
       <td>{{item.time | datefmt('yyyy-mm-dd HH:mm:ss')}}</td>
       <td>
        <a href="javascript:void(0)" rel="external nofollow" @click="del(item.id)">刪除</a>
       </td>
      </tr>
     </table>
    </div>
   </div>
  </div>
  <script>
   //定義全局過濾器
   Vue.filter("datefmt", function (input, formatstring) {
    var result = "";
    var year = input.getFullYear();
    var month = input.getMonth() + 1;
    var day = input.getDate();
    var hour = input.getHours();
    hour = hour < 10 ? "0" + hour : hour;
    var minute = input.getMinutes();
    minute = minute < 10 ? "0" + minute : minute;
    if (formatstring == 'yyyy-mm-dd') {
     result = year + "-" + month + "-" + day;
    } else {
     result = year + "-" + month + "-" + day + " " + hour + ":" + minute;
    }
    return result;
   })
   var TEMPLATE={
     options:function(){
       /**
     <a class="weui_cell" href="javascript:void(0);" rel="external nofollow" >
  <div class=weui_cell_hd >
   <i class="fa fa-credit-card fa-2x icon-color" style=width:35px;margin-right:15px;display:block ></i>
  </div>
  <div class="weui_cell_bd weui_cell_primary" >
   <p > {{HospPatientName}}
    <span style=margin-left:15px class=blue_tag >{{HospCardType}}</p>
   <p >{{HospCardNo}}</p></div>
  <div class=weui_cell_ft >
  {{HospIsDefault}}
   </div>
 </a>
             */
     }
   };
   var vm = new Vue({
    el: '#app',
    data: {
     id: '',
     name: '',
     search: '',
     list: [{
       "id": 1,
       "name": "寶馬",
       "time": new Date()
      },
      {
       "id": 2,
       "name": "奔馳",
       "time": new Date()
      }
     ]
    },
    methods: {
     del: function (id) {
      if (!confirm("是否刪除數(shù)據(jù)?")) {
       return;
      }
      //調(diào)用list.findIndex()方法,根據(jù)傳入的id獲取到這個(gè)要?jiǎng)h除數(shù)據(jù)的索引值
      var index = this.list.findIndex(function (item) {
       return item.id == id;
      });
      //調(diào)用list.splice(刪除的索引,刪除的元素個(gè)數(shù))
      this.list.splice(index, 1);
     },
     add: function () {
      //包裝成list要求的對象
      var tem = {
       id: this.id,
       name: this.name,
       time: new Date()
      };
      //將tem追加到list數(shù)組中
      this.list.push(tem);
      //清空頁面上的文本框中的數(shù)據(jù)
      this.id = "";
      this.name = "";
     }
    },
    computed: {
     searchData: function () {
      var search = this.search;
      if (search) {
       return this.list.filter(function (name) {
        return Object.keys(name).some(function (key) {
         return String(name[key]).toLowerCase().indexOf(search) > -1
        })
       })
      }
      return this.list;
     }
    }
   })
  </script>
</body>
</html>

總結(jié)

以上所述是小編給大家介紹的Vue實(shí)現(xiàn)搜索 和新聞列表功能簡單范例,希望對大家有所幫助,如果大家有任何疑問請給我留言,小編會及時(shí)回復(fù)大家的。在此也非常感謝大家對腳本之家網(wǎng)站的支持!

相關(guān)文章

最新評論

竹山县| 新民市| 伊川县| 凌源市| 广安市| 格尔木市| 昭平县| 沁源县| 宜都市| 桑日县| 嘉鱼县| 巫溪县| 文山县| 朔州市| 昌黎县| 苏尼特左旗| 濮阳市| 泸溪县| 齐河县| 洪雅县| 苍山县| 凉城县| 天祝| 澄城县| 专栏| 榆林市| 合山市| 鄂托克前旗| 衡东县| 星座| 丘北县| 绥中县| 平定县| 德江县| 桐庐县| 兴仁县| 神池县| 大荔县| 依兰县| 攀枝花市| 蒙城县|