当前位置:首页 > VUE

vue实现视频类型筛选

2026-02-25 01:00:31VUE

实现视频类型筛选功能

在Vue中实现视频类型筛选功能,可以通过以下方法完成:

数据准备 定义视频数据和筛选选项数据

data() {
  return {
    videos: [
      { id: 1, title: '视频1', type: 'movie' },
      { id: 2, title: '视频2', type: 'tvshow' },
      { id: 3, title: '视频3', type: 'documentary' }
    ],
    filterOptions: [
      { value: 'all', label: '全部' },
      { value: 'movie', label: '电影' },
      { value: 'tvshow', label: '电视剧' },
      { value: 'documentary', label: '纪录片' }
    ],
    selectedType: 'all'
  }
}

筛选逻辑 使用计算属性实现筛选功能

computed: {
  filteredVideos() {
    if (this.selectedType === 'all') {
      return this.videos
    }
    return this.videos.filter(video => video.type === this.selectedType)
  }
}

模板部分 在模板中添加筛选控件和视频列表展示

<template>
  <div>
    <select v-model="selectedType">
      <option 
        v-for="option in filterOptions" 
        :value="option.value"
        :key="option.value"
      >
        {{ option.label }}
      </option>
    </select>

    <ul>
      <li v-for="video in filteredVideos" :key="video.id">
        {{ video.title }}
      </li>
    </ul>
  </div>
</template>

进阶实现方式

使用自定义筛选组件 创建可复用的筛选组件

vue实现视频类型筛选

Vue.component('video-filter', {
  props: ['options', 'value'],
  template: `
    <select @change="$emit('input', $event.target.value)" :value="value">
      <option v-for="option in options" :value="option.value">
        {{ option.label }}
      </option>
    </select>
  `
})

在父组件中使用

<video-filter 
  :options="filterOptions" 
  v-model="selectedType"
/>

响应式筛选优化

添加搜索功能 扩展筛选功能,支持多条件筛选

data() {
  return {
    searchQuery: '',
    // 其他数据...
  }
},
computed: {
  filteredVideos() {
    let result = this.videos
    if (this.selectedType !== 'all') {
      result = result.filter(video => video.type === this.selectedType)
    }
    if (this.searchQuery) {
      const query = this.searchQuery.toLowerCase()
      result = result.filter(video => 
        video.title.toLowerCase().includes(query)
      )
    }
    return result
  }
}

添加搜索框

vue实现视频类型筛选

<input 
  type="text" 
  v-model="searchQuery" 
  placeholder="搜索视频..."
/>

性能优化建议

对于大型视频列表,可以考虑使用虚拟滚动技术优化渲染性能。可以使用第三方库如vue-virtual-scroller。

添加防抖处理搜索输入,避免频繁触发筛选计算:

import { debounce } from 'lodash'

methods: {
  handleSearch: debounce(function(query) {
    this.searchQuery = query
  }, 300)
}

在模板中使用:

<input 
  type="text" 
  @input="handleSearch($event.target.value)" 
  placeholder="搜索视频..."
/>

标签: 类型视频
分享给朋友:

相关文章

vue 实现视频

vue 实现视频

Vue 实现视频播放功能 使用 Vue 实现视频播放功能可以通过 HTML5 的 <video> 标签或第三方库(如 video.js)来实现。以下是两种常见的方法: 使用 HTML5…

h5怎么实现视频直播

h5怎么实现视频直播

实现H5视频直播的方法 H5视频直播可以通过多种技术实现,主要包括使用HTML5的<video>标签结合流媒体协议,或借助第三方库和平台。以下是几种常见方法: 使用HLS(HTTP L…

vue实现视频

vue实现视频

Vue 实现视频播放功能 Vue 可以通过集成第三方库或直接使用 HTML5 的 <video> 标签来实现视频播放功能。以下是几种常见的方法: 使用 HTML5 <video&…

vue上传视频实现

vue上传视频实现

使用 <input type="file"> 上传视频 创建文件选择控件,限制文件类型为视频格式(如 .mp4, .webm)。通过 @change 事件监听文件选择,获取 File 对象…

jquery视频

jquery视频

以下是关于 jQuery 视频学习资源的整理,涵盖免费教程、实战项目和进阶内容: 免费在线教程 W3School jQuery 教程 提供基础语法、选择器、事件处理等内容的交互式练习,适合快速入门…

vue实现录制视频

vue实现录制视频

实现视频录制的基本步骤 使用Vue实现视频录制需要结合浏览器的MediaDevices API和MediaRecorder API。以下是一个完整的实现方案: 安装必要依赖 在Vue项目中安装vu…