详解uniapp页面跳转URL传参大坑
作者:未月廿三 发布时间:2023-09-15 09:52:43
标签:uniapp,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="请输入电影名称" 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">
亲,已经到底了!
</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接收参数
<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">综合评分:</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 }}点赞</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.因为引入了组件trailerStars,此组件依赖onLoad接收的trailerId,然后去查询获取movie的详情.
2.此时trailerStars组件已经加载完毕,但是movie详情还没获取,就会产生movie.score为undefined的情况,此时需要处理
处理
首先只有movieSingle.socre >= 0时才加载组件
<block v-if="movieSingle.socre >= 0"><trailer-stars :innerScore="movieSingle.socre" showNum="0"></trailer-stars></block>
同时,trailerStars加载的时候需要放在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, //外部传入的分数
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>
来源:https://www.cnblogs.com/eternityz/p/12270011.html


猜你喜欢
- 所有人都知道select top 的用法,但很多人还不知道update top 和 delete top 怎么用。以往的做法是set row
- 自定义分页样式,不多废话,直接上代码~ html部分<div id="my_id"> &nbs
- 得益于 Python 的自动垃圾回收机制,在 Python 中创建对象时无须手动释放。这对开发者非常
- 对于个人用户来说,除了病毒和木马,网页中的隐形代码也开始严重地威胁着我们的安全,但大多数人却缺乏自我保护意识,对隐形代码的危害认识不够,甚至
- 1、需求我们的代码已经变得无法阅读,到处都是硬编码的切片索引,我们想优化他们。2、解决方案代码中如果有很多硬编码的索引值,将导致可读性和维护
- 1.引子:函数也是对象木有括号的函数那就不是在调用。def hi(name="yasoob"):return "
- Github 项目主页 工具源码分析结果:total : 15981 1568.0 == Backspace 1103.0 == Tab 1
- 大家经常用的是Adodb.Stream,但这时就有个缺陷,就是不支持断点续传了。经常看到flashget中是红脸(即不支持断点续传)其实支持
- 我们经常在B站上看到一些字符鬼畜视频,主要就是将一个视频转换成字符的样子展现出来。看起来是非常高端,但是实际实现起来确是非常简单,我们只需要
- 本文实例讲述了Python文件的读写操作。分享给大家供大家参考,具体如下:读写文件读取文件f = open('my_path/my_
- --BEGIN DISTRIBUTED TRANSACTION [transactionname]--标志一个由分布式事务处理协调器MSDT
- 在我的前一篇教程《九宫格基本布局》中,我介绍了用相对定位加绝对定位的方法来制作九宫格的基本布局。这是一种比较符合人们惯性思维的方法,好像制作
- 话说用了就要有点产出,要不然过段时间又忘了,所以在这里就记录一下试用Kafka的安装过程和php扩展的试用。实话说,如果用于队列的话,跟PH
- 本文实例讲述了js+html5操作sqlite数据库的方法。分享给大家供大家参考,具体如下://copyright by lanxyou l
- 方法1: X:\oracle\ora81\bin\wrap iname=XXX oname=XXX 方法2:9i在win2000下使用wra
- 默认情况下,PyCharm中如果有无法错误或者不符合PEP8规范代码下面会有波浪线,语法错误波浪线为红色(如下图的第10行),不符合PEP8
- js格式化金额,可选是否带千分位,可选保留精度,也是网上搜到的,但是使用没问题 /* 将数值四舍五入后格式化. @param num 数值(
- 单位内部网站第三次修改,即将进入尾声,遇到一个怪现象,就是在自定义标签中,加入链接会被替换掉成这样的格式{$GetInstallDir}ad
- 02条件语句和while循环三目运算a = 6#原判断语句if a > 5:print(True)else:print(False)#
- 猜测下面这段程序的输出:class A(object): def __init__(self):