<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>
.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;
}
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
});
}
});
}
});
这个示例展示了一个电影信息查询应用程序,包括一个输入框和一个查询按钮,用于查询指定电影的详细信息。在下方显示了电影的海报、标题、评分、类型和简介。
到这里也就结束了,希望对您有所帮助。