强制刷新页面时,浏览器会强制转换query参数的数据类型为string
首先
query传递参数常用的对象写法:
this.$router.push({ path: '/xunjian', query: { id: this.id, name: this.name } })
query可以传递多个参数,params只能传递一个参数
query可以传递任意类型的数据,传递之前不需要处理数据
问题描述
写巡检页面时,传递的id是 [数组] 的形式,第一次进入/xunjian页面时console.log(typeof this.$route.query.id)的也是[数组]类型,但强制刷新页面后,再次console.log(typeof this.$route.query.id),数据类型变成string
解决方法
在使用this.$route.query.id之前,做一次数据转化,让它变成[数组]类型
例如:
number => [ number ]
this.route.query.id = this.$route.query.id.toString().split(',').map(Number)