个人技术分享

多参数传递的两种方法:

第一种:params方法(此方法传递不会在URL路径中显示拼接)

传递参数

this.$router.push({
	name: "home",
	params:{
		key:1
	}
})

在这里插入图片描述

接收参数

		created() {
			// 获取参数
			console.log(this.$route.params.key)   //key是参数名
		},

在这里插入图片描述

第二种:query方法(此方法传递会在URL路径中显示拼接)

//传递参数
todetail(id) {
	this.$router.push({
		name: 'newsDetails',
		query: {
			id: id
		}
	})
},



//接收参数
mounted() {
	if (this.$route.query.id) {
		this.id = Number(this.$route.query.id)
	}
},