为了不让参数在地址栏显示(不使用动态路由),但又确保刷新页面后参数不会丢失,我想到一个骚操作
将第一次获取的参数,直接存到的localStorage里了,直接上代码:
<script>export default { data () { return { id: this.$route.params.id } }, created () { this.getId() }, watch: { id (val) { console.log(val) console.log('页面刷新丢失了') } }, methods: { getId () { if (this.$route.params.id === undefined) { this.id = window.localStorage.getItem('id') return } window.localStorage.setItem('id', this.$route.params.id) } }}</script>路由:
{ name: 'user-back', path: '/user-back', component: () => import('@/views/user-back') }不知道各位大佬还有没有其他的解决方法,欢迎指正