Javascript页面刷新并保留参数
我有这一页的参数来自上一页。当我刷新页面时,参数将消失,youtube视频将不显示 您可以从以下url中看到这种效果: 有没有办法保留它们以便视频正确显示Javascript页面刷新并保留参数,javascript,vue.js,nuxtjs,Javascript,Vue.js,Nuxtjs,我有这一页的参数来自上一页。当我刷新页面时,参数将消失,youtube视频将不显示 您可以从以下url中看到这种效果: 有没有办法保留它们以便视频正确显示 <template> <div> <h1 class="text-5xl mt-6">{{ $route.params.title }}</h1> <div class="bg-gray-100"> <d
<template>
<div>
<h1 class="text-5xl mt-6">{{ $route.params.title }}</h1>
<div class="bg-gray-100">
<div class="flex content-center px-16 py-8 mt-2">
<iframe
width="854"
height="480"
:src="youtubeurl"
frameborder="0"
allow="accelerometer; autoplay; clipboard-write; encrypted-media; gyroscope; picture-in-picture"
allowfullscreen
></iframe>
</div>
<p class="p-8">
{{ $route.params.description }}
</p>
</div>
</div>
</template>
<script>
export default {
props: ["ytid", "description", "title"],
mounted() {
console.log("item id");
console.log(this.ytid);
},
computed: {
youtubeurl() {
return "https://youtube.com/embed/" + this.$route.params.ytid;
}
}
};
</script>
<style scoped></style>
{{$route.params.title}
{{$route.params.description}
导出默认值{
道具:[“ytid”,“description”,“title”],
安装的(){
控制台日志(“项目id”);
console.log(this.ytid);
},
计算:{
youtubeurl(){
返回“https://youtube.com/embed/“+此.$route.params.ytid;
}
}
};
看一看。使用vuex中的存储概念,您将能够将所有数据保持在应用程序的状态
。这样,您就可以在需要时检索数据。如果您使用window.location或类似的方法,使用所有参数随意访问真实url。这不管用吗?你能为这个特定的路由添加你的路由器文件代码吗?这将有助于找出处理此问题的最佳方法。我刚刚尝试使用localstorage,刷新后它会工作。这样做可以,但fwiw,您的参数在路由中标记为id?
,但看起来您正在尝试使用this.$route.params.ytid
,因此,id
和ytid
之间存在不匹配。我会在路由中尝试id
,然后您应该能够访问它,而不管在this.$route.params.id
刷新。
<template>
<div>
<h1 class="text-5xl mt-6">{{ $route.params.title }}</h1>
<div class="bg-gray-100">
<div class="flex content-center px-16 py-8 mt-2">
<iframe
width="854"
height="480"
:src="youtubeurl"
frameborder="0"
allow="accelerometer; autoplay; clipboard-write; encrypted-media; gyroscope; picture-in-picture"
allowfullscreen
></iframe>
</div>
<p class="p-8">
{{ $route.params.description }}
</p>
</div>
</div>
</template>
<script>
export default {
props: ["ytid", "description", "title"],
mounted() {
console.log("item id");
console.log(this.ytid);
},
computed: {
youtubeurl() {
return "https://youtube.com/embed/" + this.$route.params.ytid;
}
}
};
</script>
<style scoped></style>