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

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

    • 第一步就是需要我们创建一个项目
    • [第二步找到 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
        });
      }
    });
  }
});

功能介绍

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

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

相关推荐
游戏开发爱好者85 小时前
日常开发与测试的 App 测试方法、查看设备状态、实时日志、应用数据
android·ios·小程序·https·uni-app·iphone·webview
2501_915106327 小时前
app 上架过程,安装包准备、证书与描述文件管理、安装测试、上传
android·ios·小程序·https·uni-app·iphone·webview
2501_915106327 小时前
使用 Sniffmaster TCP 抓包和 Wireshark 网络分析
网络协议·tcp/ip·ios·小程序·uni-app·wireshark·iphone
宠友信息8 小时前
2025社交+IM及时通讯社区APP仿小红书小程序
java·spring boot·小程序·uni-app·web app
“负拾捌”9 小时前
python + uniapp 结合腾讯云实现实时语音识别功能(WebSocket)
python·websocket·微信小程序·uni-app·大模型·腾讯云·语音识别
换日线°1 天前
NFC标签打开微信小程序
前端·微信小程序
光影少年1 天前
AIGC + Taro / 小程序
小程序·aigc·taro
2501_915918411 天前
在 iOS 环境下查看 App 详细信息与文件目录
android·ios·小程序·https·uni-app·iphone·webview
2501_916007471 天前
没有 Mac 用户如何上架 App Store,IPA生成、证书与描述文件管理、跨平台上传
android·macos·ios·小程序·uni-app·iphone·webview
天空属于哈夫克31 天前
Go 语言实战:构建一个企微外部群“技术贴收藏夹”小程序后端
小程序·golang·企业微信