Vue实现搜索页面

2023-11-09

目录

一、效果

二、实现


一、效果:

实现功能如下图所示:(因为被腰斩,样式未调整)

二、实现

直接上代码:

pages/Search.vue //搜索页

<template>
  <div class="search-page">
    <page-header></page-header>
    <keep-alive>                        //keep-alive包裹需更新组件
      <search-content></search-content>
    </keep-alive>
    <page-footer></page-footer>
  </div>
</template>

<script>
import PageHeader from '../components/PageHeader'
import SearchContent from '../components/SearchContent'
import PageFooter from '../components/PageFooter'
export default {
  name: 'Search',
  components: {PageHeader, SearchContent, PageFooter},
  beforeRouteUpdate (to, from, next) {
    console.log(to, from, next)
    if (to.query.input !== from.query.input) {
      next()
    }
  }
}
</script>
components/SearchContent.vue  //搜索内容组件

<template>
  <div class="search-content">
    <div class="searchContentImg">   //背景图片
      <img id="scimg" src="../assets/welcome.png" alt="">
    </div>
    <div class="secSearch">
      <div class="searchBox">    //搜索框
        <el-input v-model="input" placeholder="按关键词搜索" class="search" @keyup.enter.native="handleJump(input)"></el-input>
        <a @click="handleJump(input)"><i class="el-icon-search"></i></a>
      </div>
        //搜索内容框高度动态变化 :style
      <div v-if="searchData.length>0" class="search-list" :style="{height: heightCss}">
        <p class="total-result" :total="total" ref="pTitle">共{{ total }}条</p>
        //搜索内容列表
        <div class="search-board" ref="ulList">
          <ul class="search-fix">
            <li v-for="(item, index) in searchData" :key="index">
              <span>{{ item }}</span>
            </li>
          </ul>
        </div>
        //搜索内容分页
        <el-pagination v-if="pageshow" @size-change="handleSizeChange" @current-change="handleCurrentChange"
                       :current-page="page" :page-sizes="[1, 2,5, 10]" :page-size="limit"
                       layout="total, sizes, prev, pager, next, jumper" :total="total" class="page" ref="pageHeight">
        </el-pagination>
      </div>
      <div v-else class="search-empty">
        <ul>
          <li>
            <img src="../assets/welcome.png" class="empty-img">
          </li>
        </ul>
      </div>
    </div>
    <div class="searchImg">
      <img id="simg" src="../assets/welcome.png" alt="">
    </div>
  </div>
</template>

<script>
export default {
  name: 'SearchContent',
  data: function () {
    return {
      input: this.$route.query.input,
      keyword: this.$route.query.input,
      heightCss: '',
      list: ['1', '12', '3', '1', '12', '3', '1', '12', '3'],
      data: [],
      searchData: [],
      limit: 5,
      total: null,
      page: 1,
      pageshow: true
    }
  },
  activated () {   //初始搜索内容(由其他页面搜索内容跳转至搜索页/更新搜索内容)
    this.pageList()
    console.log('actived!')
  },
  methods: {
    handleJump (input) {
      this.$router.push(
        {path: '/search', query: {input: input}},
        onComplete => {},
        onAbort => {})
    },
    pageList () {
      // 发请求拿到数据并暂存全部数据(此处未接接口)
      this.data = ['1', '12', '3', '1', '12', '3', '1', '12', '3']
      this.page = 1
      this.pageshow = false
      this.getList()
      this.$nextTick(() => {
        this.pageshow = true
      })
      console.log('data')
      console.log(this.data)
    },
    getList () {
      //  es6过滤得到满足搜索条件的展示数据list
      let searchData = this.data.filter((item, index) =>
        item.includes(this.keyword)
      )
      console.log('keyword')
      console.log(this.keyword)
      // 过滤分页
      this.searchData = searchData.filter((item, index) =>
        index < this.page * this.limit && index >= this.limit * (this.page - 1)
      )
      // 分页的总数据
      this.total = searchData.length
      console.log('searchData')
      console.log(this.searchData)
    },
    handleSizeChange (val) {
      console.log(`每页 ${val} 条`)
      this.limit = val
      this.getList()
    },
    handleCurrentChange (val) {
      console.log(`当前页: ${val}`)
      this.page = val
      this.getList()
    },
    getHeight () {
      var heightCss1 = window.getComputedStyle(this.$refs.ullist).height // 100px
      var heightCss2 = window.getComputedStyle(this.$refs.pTitle).height // 100px
      var heightCss3 = window.getComputedStyle(this.$refs.pageHeight).height // 100px
      this.heightCss = heightCss1 + heightCss2 + heightCss3 + heightCss3
      console.log(this.heightCss)
    }
  },
  inject: ['reload'],
  watch: {
    '$route' (to, from) {
      this.input = to.query.input
      this.reload()
    }
  }
}
</script>

<style scoped>
.searchContentImg {
  width: 100%;
  height: 20%;
  top: 10%;
  left: 0;
  position: absolute;
  margin: 0 0 0 0;
  z-index: -1;
}
.secSearch {
  width: 50%;
  height: 600px;
  top: 15%;
  left: 10%;
  position: absolute;
}
.secSearch p {
  font-size: 30px;
  font-weight: 700;
  float: left;
}
.searchBox {
  width: 80%;
  top: 2%;
  position: relative;
  z-index: 10;
}
.searchBox i {
  float: right;
  left: -10px;
  position: relative;
  margin-top: -30px;
  color: #b5b5b5;
  z-index: 11;
  font-size: 18px;
  cursor: pointer;
}
#scimg {
  width: 100%;
  height: 100%;
}
.search-list {
  width: 100%;
  padding-bottom: 1.5%;
  top: 30%;
  position: absolute;
  border: 1px solid #9c9c9c;
}
.search-board {
  width: 90%;
  margin-left: 5%;
  margin-top: 8%;
  border-top: 1px solid #9c9c9c;
}
.search-board ul {
  margin-top: 1%;
}
.search-board ul li {
  list-style-type: none;
  text-align: left;
  line-height: 30px;
}
.searchImg {
  width: 20%;
  height: 100%;
  top: 40%;
  left: 65%;
  position: absolute;
  float: right;
}
#simg {
  width: 100%;
  float: left;
}
.page {
  top: 5%;
  right: 0;
  position: relative;
}
.empty-img {
  width: 100%;
  margin-top: 10%;
  left: 1%;
  position: relative;
}
.search-empty {
  width: 100%;
  height: 110%;
  top: 30%;
  position: absolute;
  border: 1px solid #9c9c9c;
}
.search-empty ul li {
  list-style-type: none;
}
.total-result {
  display: block;
  height: 24px;
  line-height: 24px;
  font-size: 24px;
  color: #333;
  width: 90%;
  text-align: left;

}
.search-list p{
  margin-top: 3%;
  margin-left: 5%;
}
</style>

代码可能有冗余未删除,若代码有误或可以改进,欢迎指正!

本文内容由网友自发贡献,版权归原作者所有,本站不承担相应法律责任。如您发现有涉嫌抄袭侵权的内容,请联系:hwhale#tublm.com(使用前将#替换为@)

Vue实现搜索页面 的相关文章

随机推荐

  • Python开发Activex组件

    Python强的功能就在于它无所不能 使用win32com模块开发window ActiveX的示例 如果你还没有装win32com模块的话 请到http python net crew skippy win32 Downloads htm
  • C0210 [2012普及组-A]质因数分解-C语言写

    题目描述 已知正整数n是两个不同的质数的乘积 试求出较大的那个质数 输入描述 输入只有一行 包含一个正整数n 输出描述 输出只有一行 包含一个正整数p 即较大的那个质数 样例输入 1 21 样例输出 1 7 提示 数据范围 对于60 的数据
  • 伪造HTTP请求中的IP信息

    很多程序需要检测客户端的IP地址 然后来授予相关的权限 比如数据库读写 文件读写 等等 其实还有一个很常见的应用 网站投票 网站投票始于2000年的左右 那时候 COM正热得发红 红得发紫 早 期的投票只要投了就行可能技术牛人们还没有想到一
  • 数据结构8.13刷题

    8 13 队列
  • vue3中实现一个动态滚动的时钟效果

    前言 用vue3如何来实现一个滚动的时钟效果呢 这里来分享下方法 注意 因为vue3很多写法都不同 所以这里多分享点东西 实现效果 实现步骤 1 路由添加 import createRouter createWebHashHistory f
  • centos7搭建verdaccio

    安装npm 百度安装或者下个包 替换一下文件名 解压安装node cd tmp mkdir p usr local node tar xvf node v8 10 0 linux x64 tar mv node v8 10 0 linux
  • 编程常用技术介绍

    在编程过程中 常常涉及到一些基础知识 这些知识与编程语言无关 但即是在进行某些基本类型的操作时必不可少的内容 如操作OFFICE的基础知识 短信发送基础知识 微信操作基础知识等 现在做一下汇总 以便后续更好地进行编程开发 1 短信操作要点
  • golang - switch

    switch 的使用 switch 语句用于基于不同条件执行不同操作 直每一个 case 分支都是唯一的 从上到下逐一测试到匹配为止 匹配项后面也不需要再加 break switch 表达式 case 表达式1 表达式2 语句块1 case
  • vue 中使用微信分享接口(简单实用)

    前言 开发微信小程序时 基本上都要接入微信的SDK 而微信也提供了非常多的接口供我们去完成我们想要的功能 微信分享功能常常是我们在开发中常见的需求之一 本文将围绕微信分享接口使用展开 给自己以后碰到需求是查阅的同时 也希望对需要的朋友提供帮
  • mysql如何查询原理_mysql 原理 ~ sql查询语句

    一 普通sql执行的具体过程 1 连接器 管理连接 权限验证 2 分析器 词法分析 语法分析 比如 数据表和数据列是否存在 别名是否有歧义 是否符合标准sql语法等 3 优化器检测 执行计划生成 索引选择 4 执行器 1 判断是否拥有操作权
  • 使用PigLatin语句分析数据

    使用PigLatin语句分析数据 load 加载数据到表中 bag foreach 对表中的每一条数据tuple进行处理 filter 相当于where group by join 连接 多表查询 generate 提取列 union in
  • 华为手机文件存放目录

    1 手机通话录音 内部存储 gt Sounds gt CallRecord路径下面
  • Python基本数据类型

    Python基本数据类型 数据类型是每种编程语言必备属性 只有给数据赋予明确的数据类型 计算机才能对数据进行处理运算 因此 正确使用数据类型是十分必要的 不同的语言 数据类型类似 但具体表示方法有所不同 以下是Python编程常用的数据类型
  • 探索珠宝商城小程序:商家如何实现线上卖珠宝

    近期 微信小程序的发展势头强劲 各行各业都在积极开发自己的小程序 以适应这个数字化的时代 珠宝行业也不例外 许多珠宝品牌都已经推出了自己的小程序 为用户提供了更加便捷 个性化的购物体验 因此 制作一款珠宝商城小程序 不仅是顺应潮流的选择 也
  • go+goquery+chromedp爬虫实现对网页数据抓取

    安装 首先 需要安装两个包 1 goquery go get github com PuerkitoBio goquery goquery包主要用于搜索界面上的元素 获取里面的值 具体操作可以参考 飞雪无痕 的 golang goquery
  • IPv6头部

    一 IPv6数据包的结构 IPv6报文 分为三个部分 头部 扩展头 上层协议数据单元 IPv4报文 头部 上层协议数据单元 IPv6头部始终存在 大小固定40字节 扩展头可能有0个或多个 且长度不固定 二 IPv6头部 1 结构 2 域 P
  • ORALCE函数:LAG()和LEAD() 分析函数详解

    Lag和Lead分析函数可以在同一次查询中取出同一字段的前N行的数据 Lag 和后N行的数据 Lead 作为独立的列 在实际应用当中 若要用到取今天和昨天的某字段差值时 Lag和Lead函数的应用就显得尤为重要 当然 这种操作可以用表的自连
  • SpringBoot整合RabbitMQ详细案例(入门RabbitMQ看这一篇就够了)

    SpringBoot整合RabbitMQ详细案例 入门RabbitMQ看这一篇就够了 1 RabbitMQ的使用场景 1 1 异步处理 1 2 应用解耦 1 3 流量削峰 2 RabbitMQ 交换机介绍 2 1 Direct exchan
  • 第3课 微信开发者工具picker标签实现动态时间选择器与地区选择器:

    微信小程序picker标签实现动态时间选择器与地区选择器 运行效果如下 wxml代码如下
  • Vue实现搜索页面

    目录 一 效果 二 实现 一 效果 实现功能如下图所示 因为被腰斩 样式未调整 二 实现 直接上代码 pages Search vue 搜索页