Vue.js实现实例搜索应用功能详细代码


Posted in Javascript onAugust 24, 2017

实例搜索应用

实现效果:

Vue.js实现实例搜索应用功能详细代码

实现代码与注释:

<!DOCTYPE html>
<html>
<head>
  <title>实例搜索</title>
  <meta charset="utf-8">
  <meta name="viewport" content="width=device-width, initial-scale=1.0">
  <style type="text/css">
    /* 隐藏没有绑定未编译的数据绑定,直到Vue实例加载 */
    [v-cloak]{
      display: none;
    }
    *{
      padding: 0;
      margin: 0;
    }
    body{
      font: 15px/1.3 'Open Sans' sans-serif;
      color: #03c03c;
      text-align: center;
    }
    a, a:visited{
      outline: none;
      color: 389dc1;
    }
    a:hover{
      text-decoration: none;
    }
    section,footer,header, aside, nav{
      display: block;
    }
    /* 搜索表单样式 */
    .bar{
      background-color: #03c03c;
       background-image:-webkit-linear-gradient(top, #03c03c, #00ed47);
      background-image:-moz-linear-gradient(top, #03c03c, #00ed47);
      background-image:linear-gradient(top, #03c03c, #00ed47);
      box-shadow: 0 1px 1px #ccc;
      border-radius: 5px;
      width: 400px;
      padding: 10px;
      margin: 45px auto 20px;
      position: relative;
    }
    .bar input{
      background: #fff no-repeat 13px 13px;
       /* search bar */
       background-image:url(data:image/png;base64,iVBORw0KGgoAAAANSUhEUgAAABAAAAAQCAYAAAAf8/9hAAAAGXRFWHRTb2Z0d2FyZQBBZG9iZSBJbWFnZVJlYWR5ccllPAAAAyBpVFh0WE1MOmNvbS5hZG9iZS54bXAAAAAAADw/eHBhY2tldCBiZWdpbj0i77u/IiBpZD0iVzVNME1wQ2VoaUh6cmVTek5UY3prYzlkIj8+IDx4OnhtcG1ldGEgeG1sbnM6eD0iYWRvYmU6bnM6bWV0YS8iIHg6eG1wdGs9IkFkb2JlIFhNUCBDb3JlIDUuMC1jMDYwIDYxLjEzNDc3NywgMjAxMC8wMi8xMi0xNzozMjowMCAgICAgICAgIj4gPHJkZjpSREYgeG1sbnM6cmRmPSJodHRwOi8vd3d3LnczLm9yZy8xOTk5LzAyLzIyLXJkZi1zeW50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j4fae5rJulF2sMXVrAsaTWttRFu4Osb+1jEDT71/ZveyhouTch2fINQL9hKefKjuYFfuznXWzXMTabyrvfyIV3M4vhXgAEAUMs7K0J9UJAAAAAASUVORK5CYII=);
       border: none;
       width: 100%;
       line-height: 19px;
       padding: 11px 0;
       border-radius: 2px;
       box-shadow: 0 2px 8px #c4c4c4 inset;
       text-align: left;
       font-size: 14px;
       font-family: inherit;
       color: #03c03c;
       font-weight: bold;
       text-indent: 40px;
       outline: none;
    }
    input:focus{
      box-shadow: -2px -2px 3px hsla(100, 0%, 0%, 0.3)
    }
    ul{
      list-style: none;
      width: 428px;
      margin: 0 auto;
      text-align: left;
    }
    ul li{
      border-bottom: 1px solid #ddd;
      padding: 10px;
      overflow: hidden;
    }
    ul li img{
      width:60px;
      height:60px;
      float:left;
      border:none;
    }
    ul li p{
      margin-left: 75px;
      font-weight: bold;
      padding-top: 12px;
      color:#6e7a7f;
    }
  </style>
</head>
<body>
<form id="main" v-cloak>
  <div class="bar">
    <!-- Create a binding between the searchString model and the text field -->
    <input type="text" v-model="searchString" placeholder="Enter your search terms" />
  </div>
  <ul>
    <!-- Render a li element for every entry in the computed filteredArticles array. -->
    <li v-for="article in filteredArticles">
      <a v-bind:href="article.url" rel="external nofollow" ><img v-bind:src="article.image" /></a>
      <p>{{article.title}}</p>
    </li>
  </ul>
</form>
<script src="https://cdnjs.cloudflare.com/ajax/libs/vue/2.0.5/vue.min.js"></script>
<script>
var demo = new Vue({
  el: '#main',
  data: {
    searchString: "",
    // The data model. These items would normally be requested via AJAX,
    // but are hardcoded here for simplicity.
    articles: [
      {
        "title": "What You Need To Know About CSS Variables",
        "url": "http://tutorialzine.com/2016/03/what-you-need-to-know-about-css-variables/",
        "image": "https://encrypted-tbn0.gstatic.com/images?q=tbn:ANd9GcQmBuM7hlJpdELwq0BSo01For8Ed0wCXQAHV9jHq-_PzRH6wF91"
      },
      {
        "title": "Freebie: 4 Great Looking Pricing Tables",
        "url": "http://tutorialzine.com/2016/02/freebie-4-great-looking-pricing-tables/",
        "image": "https://encrypted-tbn0.gstatic.com/images?q=tbn:ANd9GcTbH-xAQQDlwpR_Nig66fspeYA2QvSAoZmwn6RNgIk7aigHxBEi"
      },
      {
        "title": "20 Interesting JavaScript and CSS Libraries for February 2016",
        "url": "http://tutorialzine.com/2016/02/20-interesting-javascript-and-css-libraries-for-february-2016/",
        "image": "https://encrypted-tbn0.gstatic.com/images?q=tbn:ANd9GcQWIbs1cmJ4QeVKRQE4c_A_RZ_HJvkHRKudCBcTgerI7kmw0yPjSg"
      },
      {
        "title": "Quick Tip: The Easiest Way To Make Responsive Headers",
        "url": "http://tutorialzine.com/2016/02/quick-tip-easiest-way-to-make-responsive-headers/",
        "image": "https://encrypted-tbn0.gstatic.com/images?q=tbn:ANd9GcQltg_0PzWsXoBeIg7iqNwbruKI9WgXT2AzhR1BZM7Mim2TMdH0cA"
      },
      {
        "title": "Learn SQL In 20 Minutes",
        "url": "http://tutorialzine.com/2016/01/learn-sql-in-20-minutes/",
        "image": "https://encrypted-tbn0.gstatic.com/images?q=tbn:ANd9GcRZaAHyHFL4NobdtmsGDoEUovpEptRWqTlvmiUCyf0jfG4bW-Pa4A"
      },
      {
        "title": "Creating Your First Desktop App With HTML, JS and Electron",
        "url": "http://tutorialzine.com/2015/12/creating-your-first-desktop-app-with-html-js-and-electron/",
        "image": "https://encrypted-tbn0.gstatic.com/images?q=tbn:ANd9GcQApR5hqB7iBddDFcXRprwlk60yfBk9dOxpAHcAC_4rDl27sYj-"
      }
    ]
  },
  computed: {
    // A computed property that holds only those articles that match the searchString.
    filteredArticles: function () {
      var articles_array = this.articles,
        searchString = this.searchString;
      if(!searchString){
        return articles_array;
      }
      searchString = searchString.trim().toLowerCase();
      articles_array = articles_array.filter(function(item){
        if(item.title.toLowerCase().indexOf(searchString) !== -1){
          return item;
        }
      })
      // Return an array with the filtered data.
      return articles_array;;
    }
  }
});
</script>
</body>
</html>

总结

以上所述是小编给大家介绍的Vue.js实现实例搜索应用功能详细代码,希望对大家有所帮助,如果大家有任何疑问请给我留言,小编会及时回复大家的。在此也非常感谢大家对三水点靠木网站的支持!

Javascript 相关文章推荐
js操作Xml(向服务器发送Xml,处理服务器返回的Xml)(IE下有效)
Jan 30 Javascript
JQuery UI DatePicker中z-index默认为1的解决办法
Sep 28 Javascript
HTML DOM的nodeType值介绍
Mar 31 Javascript
JavaScript之引用类型介绍
Aug 10 Javascript
用jquery.sortElements实现table排序
May 04 Javascript
JavaScript SHA-256加密算法详细代码
Oct 06 Javascript
BootStrap Table后台分页时前台删除最后一页所有数据refresh刷新后无数据问题
Dec 28 Javascript
jquery获取下拉框中的循环值
Feb 08 Javascript
jQuery插件echarts实现的循环生成图效果示例【附demo源码下载】
Mar 04 Javascript
详解Vue使用 vue-cli 搭建项目
Apr 20 Javascript
Vue $emit $refs子父组件间方法的调用实例
Sep 12 Javascript
javascript实现摄像头拍照预览
Sep 30 Javascript
实例详解JSON取值(key是中文或者数字)方式
Aug 24 #Javascript
JSON创建键值对(key是中文或者数字)方式详解
Aug 24 #Javascript
使用jquery+iframe做一个ajax上传效果(实例)
Aug 24 #jQuery
webpack学习笔记之优化缓存、合并、懒加载
Aug 24 #Javascript
基于JavaScript实现新增内容滚动播放效果附完整代码
Aug 24 #Javascript
快速理解 JavaScript 中的 LHS 和 RHS 查询的用法
Aug 24 #Javascript
vue不通过路由直接获取url中参数的方法示例
Aug 24 #Javascript
You might like
PHP过滤黑名单关键字的方法
2014/12/01 PHP
ecshop 2.72如何修改后台访问地址
2015/03/03 PHP
php curl 上传文件代码实例
2015/04/27 PHP
php实现随机生成易于记忆的密码
2015/06/19 PHP
php文件系统处理方法小结
2016/05/23 PHP
利用jQuery接受和处理xml数据的代码(.net)
2011/03/28 Javascript
jQuery中unbind()方法用法实例
2015/01/19 Javascript
原生js结合html5制作简易的双色子游戏
2015/03/30 Javascript
node.js 使用ejs模板引擎时后缀换成.html
2015/04/22 Javascript
JavaScript与java语言有什么不同
2016/09/22 Javascript
深入探究node之Transform
2017/07/20 Javascript
Vue父子组件双向绑定传值的实现方法
2018/07/31 Javascript
vue 导航锚点_点击平滑滚动,导航栏对应变化详解
2020/08/10 Javascript
[01:14]2014DOTA2展望TI 剑指西雅图newbee战队专访
2014/06/30 DOTA
python文件操作相关知识点总结整理
2016/02/22 Python
浅谈django model postgres的json字段编码问题
2018/01/05 Python
python ipset管理 增删白名单的方法
2019/01/14 Python
Python3.5面向对象编程图文与实例详解
2019/04/24 Python
Python3+Pycharm+PyQt5环境搭建步骤图文详解
2019/05/29 Python
Scrapy中如何向Spider传入参数的方法实现
2020/09/28 Python
CSS3支持IE6, 7, and 8的边框border属性
2012/12/28 HTML / CSS
浏览器实现移动端高性能css3动画(开启gpu加速)
2013/12/23 HTML / CSS
什么是servlet链?
2014/07/13 面试题
护士个人简历自荐信
2013/10/18 职场文书
工艺工程师工作职责
2013/11/23 职场文书
新浪微博实习心得体会
2014/01/27 职场文书
社区端午节活动方案
2014/01/28 职场文书
社会调查研究计划书
2014/05/01 职场文书
企业形象策划方案
2014/05/29 职场文书
5s标语大全
2014/06/23 职场文书
社会体育专业大学生职业生涯规划书
2014/09/17 职场文书
校园学雷锋广播稿
2014/10/08 职场文书
统计员岗位职责范本
2015/04/14 职场文书
学生会招新宣传语
2015/07/13 职场文书
索尼ICF-36收音机评测
2022/04/30 无线电
MySql数据库触发器使用教程
2022/06/01 MySQL