vue 跳转页面传参的时候参数值为undefined的解决方法

    科技2022-07-13  144

    错误代码如下:

    跳转之前的页面:

    clickScan(index,row) { this.$router.push({ path: '/biz/AssociationAcitvityEnroll', params: { associationId: row.associationId } }) },

    跳转之后的页面

    mounted: function () { this.associationId = this.$route.params.associationId console.log(this.associationId) },

    我们会发现this.assocationId的值为undefined,原因是在跳转之前没有给name属性的值, 正确的代码如下:

    跳转之前的页面:

    clickScan(index,row) { this.$router.push({ name: '社团活动',//这里必须有,没有的话传过去的值为undefined path: '/biz/AssociationAcitvityEnroll', params: { associationId: row.associationId } }) },

    name属性值就是你在router文件夹下,index.js文件中配置路由中的name属性

    Processed: 0.014, SQL: 8