<ruby id="bdb3f"></ruby>

    <p id="bdb3f"><cite id="bdb3f"></cite></p>

      <p id="bdb3f"><cite id="bdb3f"><th id="bdb3f"></th></cite></p><p id="bdb3f"></p>
        <p id="bdb3f"><cite id="bdb3f"></cite></p>

          <pre id="bdb3f"></pre>
          <pre id="bdb3f"><del id="bdb3f"><thead id="bdb3f"></thead></del></pre>

          <ruby id="bdb3f"><mark id="bdb3f"></mark></ruby><ruby id="bdb3f"></ruby>
          <pre id="bdb3f"><pre id="bdb3f"><mark id="bdb3f"></mark></pre></pre><output id="bdb3f"></output><p id="bdb3f"></p><p id="bdb3f"></p>

          <pre id="bdb3f"><del id="bdb3f"><progress id="bdb3f"></progress></del></pre>

                <ruby id="bdb3f"></ruby>

                ??一站式輕松地調用各大LLM模型接口,支持GPT4、智譜、豆包、星火、月之暗面及文生圖、文生視頻 廣告
                ### 1. 將發送http請求 星星的顯示個數 封裝在一個文件夾下的utils.js中 ~~~ //app.js 創建全局變量 globalData:{ doubanUrl:"https://douban.uieee.com/v2/movie/" } }); 使用方法 const app = getApp(); const douban = app.globalData.doubanUrl; //utils.js 封裝http函數 callback為回掉函數,傳參時callback的名字可以自己起 要使用this.**()調用 然后再后面寫函數內容 function http(url, callback, type) { wx.request({ url, header: { 'Content-Type': 'json' }, success: function (res) { callback(res,type); //返回請求的數據和傳入的變量 } }); } 星星的顯示個數 function star(stars) { var value = stars.slice(0, 1); var arr = []; for (let i = 0; i < 5; i++) { if (i < value) { arr.push(1); } else { arr.push(0); } } return arr; } 模塊化es6語法: 導出 export default { http, star } ~~~ ### 2. 在顯示頁面的js中 ~~~ // pages/movies/movies.js const app = getApp(); const douban = app.globalData.doubanUrl; //導出模塊的使用 import utils from "../../utils/utils"; const http = utils.http; var star = utils.star; Page({ /** * 頁面的初始數據 */ //data是用來裝數據的可以裝變量 a:null,可以裝數組 arr:[], 可以裝對象"a":{},對象里面可以裝數組、變量 data: { "in_theaters": {}, "coming_soon": {}, "top250": {} }, /** * 生命周期函數--監聽頁面加載 */ onLoad: function (options) { //加載時的加載動畫 最后停止時用 wx.hideLoading();在onload函數中使用 wx.showLoading({ title:"加載數據" }); var count = "?start=0&count=3"; var inTheatersUrl = douban + "in_theaters" + count; var comingSoon = douban+"coming_soon"+count; var top250 = douban+"top250"+count; http(inTheatersUrl, this.handleData,"in_theaters"); http(comingSoon, this.handleData,"coming_soon"); http(top250, this.handleData,"top250"); }, handleData(res,type) { var title = res.data.title; var subjects = res.data.subjects; var movies = []; subjects.forEach(ele=>{ var average = ele.rating.average; var stars = star(ele.rating.stars); var title = ele.title; var imgUrl = ele.images.small; var temp = { average, stars, title, imgUrl }; movies.push(temp); }) //創建一個對象用來根據傳入的不同變量來設置對象名和對象里的數據 因為上方的data中存放的是多個對象要使用對象的賦值方法 var readyData={}; readyData[type]= { movies, title, type }; this.setData(readyData); wx.hideLoading(); }, // 跳轉到更多頁面 綁定一個點擊事件 頁面要加catchtap="more" data-type="{{type}}" data-title="{{title}}" 后面代表調轉頁面帶兩個參數 more(event){ var type = event.currentTarget.dataset.type; var title = event.currentTarget.dataset.title; wx.navigateTo({ url: 'movies-more/movies-more?type='+type+"&title="+title }); } }) ~~~ ### 3.顯示頁面的嵌套頁面 ~~~ //movies <import src="movies-grid/movies-grid-template.wxml"></import> <template is="moviesGridTemplate" data="{{...in_theaters}}"></template> <template is="moviesGridTemplate" data="{{...coming_soon}}"></template> <template is="moviesGridTemplate" data="{{...top250}}"></template> @import "movies-grid/movies-grid-template.wxss"; page{ height:100%; background: #eee; } //movies-grid-template <import src="../movies-item/movies-item-template"></import> <template name="moviesGridTemplate"> <view class="movies-grid"> <view class="more-title"> <text>{{title}}</text> <text class="more" catchtap="more" data-type="{{type}}" data-title="{{title}}">更多</text> </view> <view class="movies-grid-item"> <block wx:for="{{movies}}" wx:key="index" > <template is="moviesItemTemplate" data="{{...item}}"></template> </block> </view> </view> </template> </template> @import "../movies-item/movies-item-template.wxss"; .movies-grid{ display: flex; flex-direction: column; padding:16rpx; background: #fff; margin-top: 10px; margin-bottom: 10px; } .more-title,.movies-grid-item{ display: flex; justify-content:space-between; margin-top: 10px; margin-bottom: 10px; } .movies-grid text{ font-size: 25rpx; } .more{ cursor: pointer; color:#405F80 } //movies-item-template <import src="../star/star-template"></import> <template name="moviesItemTemplate"> <view class="movies-item"> <image src="{{imgUrl}}" class="banner" mode="aspectFit"></image> <text class="head">{{title}}</text> <view class="evaluate"> <template is="starTemplate" data="{{stars}}"></template><text>{{average}}</text> </view> </view> </template> @import "../star/star-template"; .movies-item .evaluate{ display: flex; } .movies-item{ display: flex; flex-direction: column; cursor: pointer; } .evaluate{ align-items: center; } .evaluate text{ margin-left:10rpx; } .movies-item>.banner{ width:230rpx; height:300rpx; } .movies-item .head{ margin-top:10px; margin-bottom: 10px; } //star-template <template name="starTemplate"> <view class="star"> <block wx:for="{{stars}}"> <image wx:if="{{item==1}}" src="/images/icon/star.png"></image> <image wx:else src="/images/icon/none-star.png"></image> </block> </view> </template> .star image{ width:20rpx; height:20rpx; } .star{ display: flex; } //movies-more // pages/movies/movies-more/movies-more.js var douban = getApp().globalData.doubanUrl; import utils from "../../../utils/utils"; var http = utils.http; var star = utils.star; Page({ data: { }, /** * 生命周期函數--監聽頁面加載 */ onLoad: function (options) { var type = options.type; var title = options.title; console.log(title); var url = douban + type; http(url, this.handleData); /* 設置標題 */ wx.setNavigationBarTitle({ title }); }, handleData(res) { var title = res.data.title; var subjects = res.data.subjects; var movies = []; subjects.forEach(ele => { var average = ele.rating.average; var stars = star(ele.rating.stars); var title = ele.title; var imgUrl = ele.images.small; var temp = { average, stars, title, imgUrl }; movies.push(temp); }) this.setData({ movies, title }) } }) wxml <import src="../movies-item/movies-item-template"></import> <view class='movies-more'> <block wx:for="{{movies}}" wx:key="index" > <template is="moviesItemTemplate" data="{{...item}}"></template> </block> </view> @import "../movies-item/movies-item-template"; .movies-more{ display: flex; flex-wrap: wrap; justify-content: space-between; } .movies-more .movies-item{ margin: 15rpx auto 30rpx; } ~~~
                  <ruby id="bdb3f"></ruby>

                  <p id="bdb3f"><cite id="bdb3f"></cite></p>

                    <p id="bdb3f"><cite id="bdb3f"><th id="bdb3f"></th></cite></p><p id="bdb3f"></p>
                      <p id="bdb3f"><cite id="bdb3f"></cite></p>

                        <pre id="bdb3f"></pre>
                        <pre id="bdb3f"><del id="bdb3f"><thead id="bdb3f"></thead></del></pre>

                        <ruby id="bdb3f"><mark id="bdb3f"></mark></ruby><ruby id="bdb3f"></ruby>
                        <pre id="bdb3f"><pre id="bdb3f"><mark id="bdb3f"></mark></pre></pre><output id="bdb3f"></output><p id="bdb3f"></p><p id="bdb3f"></p>

                        <pre id="bdb3f"><del id="bdb3f"><progress id="bdb3f"></progress></del></pre>

                              <ruby id="bdb3f"></ruby>

                              哎呀哎呀视频在线观看