当前位置:首页 > VUE

vue实现影院

2026-03-07 09:54:49VUE

Vue 实现影院功能

影院页面布局

使用 Vue 组件化开发影院页面,通常包括影院列表、筛选条件、地图定位等功能模块。通过 v-for 渲染影院列表数据,结合 v-ifv-show 控制筛选条件的显示。

<template>
  <div class="cinema-container">
    <div class="filter-bar">
      <button @click="toggleFilter">筛选</button>
      <div v-show="showFilter" class="filter-options">
        <input type="text" v-model="searchQuery" placeholder="搜索影院">
        <select v-model="selectedRegion">
          <option v-for="region in regions" :key="region">{{ region }}</option>
        </select>
      </div>
    </div>
    <ul class="cinema-list">
      <li v-for="cinema in filteredCinemas" :key="cinema.id">
        <h3>{{ cinema.name }}</h3>
        <p>{{ cinema.address }}</p>
      </li>
    </ul>
  </div>
</template>

数据获取与处理

通过 Vue 的 datamethods 定义影院数据和筛选逻辑。使用 computed 属性实现动态过滤影院列表。

<script>
export default {
  data() {
    return {
      cinemas: [],
      searchQuery: '',
      selectedRegion: '全部',
      regions: ['全部', '朝阳区', '海淀区', '东城区'],
      showFilter: false
    }
  },
  computed: {
    filteredCinemas() {
      return this.cinemas.filter(cinema => {
        const matchesSearch = cinema.name.includes(this.searchQuery) || 
                             cinema.address.includes(this.searchQuery);
        const matchesRegion = this.selectedRegion === '全部' || 
                             cinema.region === this.selectedRegion;
        return matchesSearch && matchesRegion;
      });
    }
  },
  methods: {
    toggleFilter() {
      this.showFilter = !this.showFilter;
    },
    fetchCinemas() {
      // 模拟 API 请求
      this.cinemas = [
        { id: 1, name: '万达影城', address: '朝阳区建国路93号', region: '朝阳区' },
        { id: 2, name: 'UME国际影城', address: '海淀区中关村大街19号', region: '海淀区' }
      ];
    }
  },
  created() {
    this.fetchCinemas();
  }
}
</script>

影院详情页

通过 Vue Router 实现影院详情页的跳转,使用动态路由参数传递影院 ID。

// router.js
{
  path: '/cinema/:id',
  name: 'CinemaDetail',
  component: () => import('./views/CinemaDetail.vue')
}
<!-- CinemaDetail.vue -->
<template>
  <div v-if="cinema">
    <h1>{{ cinema.name }}</h1>
    <p>{{ cinema.address }}</p>
    <!-- 影院座位选择等更多功能 -->
  </div>
</template>

<script>
export default {
  data() {
    return {
      cinema: null
    }
  },
  created() {
    const cinemaId = this.$route.params.id;
    this.fetchCinema(cinemaId);
  },
  methods: {
    fetchCinema(id) {
      // 根据 ID 获取影院详情
    }
  }
}
</script>

影院座位选择

实现影院座位选择功能,通常使用 SVG 或 Canvas 绘制座位图,并通过 Vue 管理选座状态。

<template>
  <div class="seat-map">
    <div 
      v-for="seat in seats" 
      :key="seat.id" 
      :class="['seat', { 'selected': seat.selected }]"
      @click="selectSeat(seat)"
    >
      {{ seat.number }}
    </div>
  </div>
</template>

<script>
export default {
  data() {
    return {
      seats: [
        { id: 1, number: 'A1', selected: false },
        { id: 2, number: 'A2', selected: false }
      ]
    }
  },
  methods: {
    selectSeat(seat) {
      seat.selected = !seat.selected;
    }
  }
}
</script>

样式与交互优化

使用 CSS 或 UI 框架(如 Element UI、Vant)美化影院页面,添加加载状态、错误处理等交互细节。

vue实现影院

.cinema-list {
  list-style: none;
  padding: 0;
}
.cinema-list li {
  padding: 15px;
  border-bottom: 1px solid #eee;
}
.seat {
  display: inline-block;
  width: 30px;
  height: 30px;
  margin: 5px;
  background: #ccc;
  text-align: center;
  line-height: 30px;
  cursor: pointer;
}
.seat.selected {
  background: #42b983;
}

标签: 影院vue
分享给朋友:

相关文章

vue 实现jqslidedown

vue 实现jqslidedown

在 Vue 中实现类似 jQuery 的 slideDown 效果,可以通过 Vue 的过渡系统或 CSS 动画结合动态样式绑定来实现。以下是几种实现方式: 使用 Vue Transition 组件…

vue实现截图

vue实现截图

Vue 实现截图的方法 使用 html2canvas 库 安装 html2canvas 库: npm install html2canvas 在 Vue 组件中使用: import html2ca…

vue实现handsontable

vue实现handsontable

Vue 中实现 Handsontable 要在 Vue 项目中集成 Handsontable,可以使用官方提供的 @handsontable/vue 封装库。以下是一个完整的实现步骤。 安装依赖 确…

vue 全景实现

vue 全景实现

Vue 全景实现方案 在Vue中实现全景效果,通常需要结合WebGL或第三方库来处理3D场景渲染。以下是几种常见方法: 使用Three.js库 Three.js是一个强大的WebGL库,适合创建3D…

vue 实现分屏

vue 实现分屏

Vue 实现分屏的方法 使用 CSS Flexbox 或 Grid 布局 通过 CSS Flexbox 或 Grid 布局可以轻松实现分屏效果。在 Vue 组件中定义两个或多个区域,并使用 CSS 控…

vue filter 实现

vue filter 实现

在 Vue.js 中,过滤器(Filter)是一种用于文本格式化的功能,可以在模板中直接使用。以下是实现过滤器的详细方法: 全局过滤器注册 通过 Vue.filter 方法注册全局过滤器,可在所有组…