微信小程序实现一个电影信息查询的应用程序

微信小程序实现一个电影信息查询的应用程序

    • 第一步就是需要我们创建一个项目
    • [第二步找到 pages/index/index.wxml 文件](#第二步找到 pages/index/index.wxml 文件)
    • [第三步在 pages/index/index.wxss 文件中添加以下样式](#第三步在 pages/index/index.wxss 文件中添加以下样式)
    • [第四步在 pages/index/index.js 文件中添加下面代码](#第四步在 pages/index/index.js 文件中添加下面代码)
    • 功能介绍

第一步就是需要我们创建一个项目

第二步找到 pages/index/index.wxml 文件

javascript 复制代码
<view class="container">
  <view class="header">
    <input class="input" placeholder="请输入电影名称" bindinput="onInput" value="{{ inputValue }}" />
    <button class="button" bindtap="searchMovie">查询</button>
  </view>
  <view class="movie-info" wx:if="{{ movieName }}">
    <image class="poster" src="{{ moviePoster }}" mode="aspectFill" />
    <view class="info">
      <view class="title">{{ movieTitle }}</view>
      <view class="rating">评分:{{ movieRating }}</view>
      <view class="genres">类型:{{ movieGenres }}</view>
      <view class="summary">{{ movieSummary }}</view>
    </view>
  </view>
</view>

第三步在 pages/index/index.wxss 文件中添加以下样式

javascript 复制代码
.container {
  display: flex;
  flex-direction: column;
  align-items: center;
  justify-content: center;
  height: 100vh;
}

.header {
  display: flex;
  align-items: center;
  margin-bottom: 20px;
}

.input {
  flex-grow: 1;
  padding: 10px;
  border: 1px solid #CCC;
  border-radius: 4px;
}

.button {
  padding: 10px 20px;
  margin-left: 10px;
  background-color: #007AFF;
  color: #FFF;
  border-radius: 4px;
}

.movie-info {
  display: flex;
  align-items: center;
}

.poster {
  width: 150px;
  height: 200px;
  margin-right: 20px;
}

.info {
  flex-grow: 1;
}

.title {
  font-size: 24px;
  margin-bottom: 10px;
}

.rating {
  font-size: 16px;
  margin-bottom: 10px;
}

.genres {
  font-size: 16px;
  margin-bottom: 10px;
}

.summary {
  font-size: 14px;
}

第四步在 pages/index/index.js 文件中添加下面代码

javascript 复制代码
Page({
  data: {
    inputValue: '', // 输入框的值
    movieName: '', // 电影名称
    moviePoster: '', // 电影海报
    movieTitle: '', // 电影标题
    movieRating: '', // 电影评分
    movieGenres: '', // 电影类型
    movieSummary: '' // 电影简介
  },
  onInput(e) {
    this.setData({
      inputValue: e.detail.value
    });
  },
  searchMovie() {
    const that = this;
    wx.request({
      url: 'https://api.douban.com/v2/movie/search',
      data: {
        q: this.data.inputValue,
        count: 1
      },
      success(res) {
        const movie = res.data.subjects[0];
        that.setData({
          movieName: movie.title,
          moviePoster: movie.images.large,
          movieTitle: movie.original_title,
          movieRating: movie.rating.average,
          movieGenres: movie.genres.join(' / '),
          movieSummary: movie.summary
        });
      }
    });
  }
});

功能介绍

这个示例展示了一个电影信息查询应用程序,包括一个输入框和一个查询按钮,用于查询指定电影的详细信息。在下方显示了电影的海报、标题、评分、类型和简介。

到这里也就结束了,希望对您有所帮助。

相关推荐
凡科网小帆5 小时前
2026小程序商城做的比较好的品牌,怎么选小程序商城品牌
小程序·小程序商城
2501_915909066 小时前
iOS 证书创建与管理 类型限制 p12 密码与云备份实操
android·ios·小程序·https·uni-app·iphone·webview
拖孩1 天前
用 AI 重解千年观音灵签,做了一个微信小程序,每天摇一摇,命运给你回应
前端·后端·微信小程序
黄华SJ520it1 天前
顶俏洗衣液模式制度开发介绍:S2B2C社交分销+多门店核销系统全解析
前端·数据库·小程序·零售·系统开发
北极糊的狐1 天前
钉钉小程序报错data.formatTime is not a function是因为 axml 模板中不能直接调用 Page 内自定义方法!
java·小程序·钉钉
java1234_小锋1 天前
【免费】微信小程序网约车(打车,在线叫车,移动出行)系统(SpringBoot4+Vue3) 锋哥原创出品,必属精品
微信小程序·网约车·在线叫车·移动出行
show4332 天前
多格式导出怎么做?2026免费小程序TXT/SRT实践
开发语言·小程序·c#
AI砖家2 天前
AI编程—微信小程序开发规范
微信小程序·小程序·notepad++·ai编程
show4333 天前
2026小程序端视频转文字技术对比:识别引擎精度实测
小程序·音视频
sam-zy3 天前
微信小程序+ESP8266+Arduino 开发智能插座,有本地OTA功能
微信小程序·小程序