詳解uniapp頁(yè)面跳轉(zhuǎn)URL傳參大坑
案例
展示電影詳情,傳遞電影的id.從search.vue傳遞到movie.vue
methods: { showMovie(e){ var trailerid = e.currentTarget.dataset.trailerid; // console.log(trailerid); uni.navigateTo({ url: '../movie/movie?trailerId='+trailerid, success: res => {}, fail: () => {}, complete: () => {} }); } }
search.vue全部文件
<template> <view class="page"> <view class="search-block"> <view class="search-ico-wrapper"> <image src="../../static/icos/search.png" class="search-ico"></image> </view> <input type="text" value="" placeholder="請(qǐng)輸入電影名稱" maxlength="10" class="search-text" confirm-type="search" @confirm="searchMe" /> </view> <view class="movie-list page-block"> <view v-for="movie in resultList" :key="movie.id" class="movie-wrapper"> <image :src="movie.cover" :data-trailerId="movie.id" @click="showMovie" class="poster"></image> </view> <!-- <view class="movie-wrapper"> <image src="../../static/poster/civilwar.jpg" class="poster"></image> </view> --> </view> <view class="bottom-tip" v-if="show"> 親,已經(jīng)到底了! </view> </view> </template> <script> import {DataMixin} from "../../common/DataMixin.js" export default { mixins:[DataMixin], data() { return { keyWords: '', show: false, resultList: [] } }, onLoad() { this.resultList = this.list; }, onPullDownRefresh(e) { uni.showLoading({ mask: true }); uni.showNavigationBarLoading(); this.resultList = this.list; this.show = false; this.queryByKeyWords(); uni.stopPullDownRefresh(); uni.hideLoading(); uni.hideNavigationBarLoading(); }, onReachBottom() { uni.showLoading({ mask: true }); uni.showNavigationBarLoading(); this.resultList = [...this.list, ...this.appendList]; this.show = true; uni.stopPullDownRefresh(); uni.hideLoading(); uni.hideNavigationBarLoading(); }, methods: { showMovie(e){ var trailerid = e.currentTarget.dataset.trailerid; uni.navigateTo({ url: `../movie/movie?trailerId=${trailerid}`, success: res => {}, fail: () => {}, complete: () => {} }); }, queryByKeyWords(){ var tempList = [...this.list, ...this.appendList]; this.resultList = []; if (this.keyWords) { tempList.forEach(movie => { if (movie.name.indexOf(this.keyWords) != -1) { this.resultList.push(movie) } }) } else { this.resultList = this.list; } }, searchMe(e) { this.show = false; var value = e.detail.value; this.keyWords = value; this.queryByKeyWords(); } } } </script> <style> @import url("search.css"); </style>
movie接收參數(shù)
<template> <view class="page"> <!-- 視頻播放start --> <view class="player"><video :src="movieSingle.trailer" :poster="movieSingle.poster" class="movie" controls></video></view> <!-- 視頻播放end --> <!-- 影片基本信息start --> <view class="movie-info"> <image :src="movieSingle.cover" class="cover"></image> <view class="movie-desc"> <view class="title">{{ movieSingle.name }}</view> <view class="basic-info">{{ movieSingle.basicInfo }}</view> <view class="basic-info">{{ movieSingle.originalName }}</view> <view class="basic-info">{{ movieSingle.totalTime }}</view> <view class="basic-info">{{ movieSingle.releaseDate }}</view> <view class="score-block"> <view class="big-score"> <view class="score-words">綜合評(píng)分:</view> <view class="movie-score">{{ movieSingle.score }}</view> </view> <view class="score-stars"> <block v-if="movieSingle.score >= 0"><trailer-stars :innerScore="movieSingle.score" showNum="0"></trailer-stars></block> <view class="prise-counts">{{ movieSingle.priseCounts }}點(diǎn)贊</view> </view> </view> </view> </view> <!-- 影片基本信息end --> </view> </template> <script> import trailerStars from '../../components/trailerStars/trailerStars.vue'; import { DataMixin } from '../../common/DataMixin.js'; export default { name: '', mixins: [DataMixin], components: { trailerStars }, data() { return { movieSingle: {}, trailerId: '' }; }, onLoad(params) { this.trailerId = params.trailerId; var tempList = [...this.list, ...this.appendList]; tempList.forEach(movie => { if (movie.id == this.trailerId) { this.movieSingle = movie; } }); }, methods: {} }; </script> <style> @import url('movie.css'); </style>
詳解
1.因?yàn)橐肓私M件trailerStars,此組件依賴onLoad接收的trailerId,然后去查詢獲取movie的詳情.
2.此時(shí)trailerStars組件已經(jīng)加載完畢,但是movie詳情還沒(méi)獲取,就會(huì)產(chǎn)生movie.score為undefined的情況,此時(shí)需要處理
處理
首先只有movieSingle.socre >= 0時(shí)才加載組件
<block v-if="movieSingle.socre >= 0"><trailer-stars :innerScore="movieSingle.socre" showNum="0"></trailer-stars></block>
同時(shí),trailerStars加載的時(shí)候需要放在mounted中加載
<template> <view class="movie-score-wrapper"> <image v-for="yellow in yelloScore" src="../../static/icos/star-yellow.png" class="star-ico"></image> <image v-for="gray in grayScore" src="../../static/icos/star-gray.png" class="star-ico"></image> <view class="movie-score" v-if="showNum==1">{{innerScore}}</view> </view> </view> </template> <script> export default { name: "trailerStars", props: { innerScore: 0, //外部傳入的分?jǐn)?shù) showNum: 0, //是否顯示,1顯示,0不顯示 }, data() { return { yelloScore: 0, grayScore: 0, } }, mounted() { console.log("this.innerScore=" + this.innerScore) var tempScore = 0; if (this.innerScore != null && this.innerScore != undefined && this.innerScore != '') { tempScore = this.innerScore; } var yelloScore = parseInt(tempScore / 2); var grayScore = 5 - yelloScore; this.yelloScore = yelloScore; this.grayScore = grayScore; } } </script> <style> .movie-score-wrapper { display: flex; flex-direction: row; } .star-ico { width: 20rpx; height: 20rpx; margin-top: 6rpx; } .movie-score { font-size: 12px; color: #808080; margin-left: 8rpx; } </style>
到此這篇關(guān)于詳解uniapp頁(yè)面跳轉(zhuǎn)URL傳參大坑的文章就介紹到這了,更多相關(guān)uniapp URL傳參內(nèi)容請(qǐng)搜索腳本之家以前的文章或繼續(xù)瀏覽下面的相關(guān)文章希望大家以后多多支持腳本之家!
相關(guān)文章
人人網(wǎng)javascript面試題 可以提前實(shí)現(xiàn)下
JavaScript面試題要求:以下題目必須從一至四題中,選出三道題,使用原生代碼實(shí)現(xiàn),不可使用任何框架,第五題為選作題2012-01-01javascript笛卡爾積算法實(shí)現(xiàn)方法
這篇文章主要介紹了javascript笛卡爾積算法實(shí)現(xiàn)方法,實(shí)例分析了笛卡爾積算法的javascript實(shí)現(xiàn)技巧,具有一定參考借鑒價(jià)值,需要的朋友可以參考下2015-04-04js與vue如何實(shí)現(xiàn)自動(dòng)全屏顯示效果
這篇文章主要給大家介紹了關(guān)于js與vue如何實(shí)現(xiàn)自動(dòng)全屏顯示效果的相關(guān)資料,在vue項(xiàng)目中做一個(gè)可以控制頁(yè)面全屏展示的效果,文中通過(guò)代碼介紹的非常詳細(xì),需要的朋友可以參考下2023-12-12javascript 類方法定義還是有點(diǎn)區(qū)別
這兩個(gè)定義都可以,不過(guò)后者對(duì)FF貌似好一些,前者在FF下可能出現(xiàn)missing before formal parameters錯(cuò)誤,導(dǎo)致js無(wú)法執(zhí)行。2009-04-04underscore之Chaining_動(dòng)力節(jié)點(diǎn)Java學(xué)院整理
本文通過(guò)文字說(shuō)明與代碼的形式給大家介紹了underscore之Chaining的相關(guān)知識(shí),感興趣的朋友一起學(xué)習(xí)吧2017-07-07NodeJS Express框架中處理404頁(yè)面一個(gè)方式
這篇文章主要介紹了NodeJS Express框架中處理404頁(yè)面一個(gè)方式,原理就是把404路由放在最后匹配,也就是路由中沒(méi)有定義的全部轉(zhuǎn)到404頁(yè)面,需要的朋友可以參考下2014-05-05JS獲取鼠標(biāo)坐標(biāo)并且根據(jù)鼠標(biāo)位置不同彈出不同內(nèi)容
這篇文章主要介紹了js獲取鼠標(biāo)坐標(biāo)并且根據(jù)鼠標(biāo)位置不同彈出不同內(nèi)容的實(shí)例代碼,需要的朋友可以參考下2017-06-06