wim15013442181 2023-04-15 12:07 采纳率: 36.4%
浏览 78
已结题

数据字典,mapGetters,this.$store.dispatch 传递参数

数据字典,不同页面传递参数。 dict.vue, 页面的id传递到 dictValue.vue 获取list.


//dict.vue 传参
      showDictValue (item) {
        this.$store.dispatch('getSystemDictId', item.id)
        this.$router.push({
          name: 'dictValue'
        })
      },
 
//dictValue.vue 接收参数.
import { mapGetters } from 'vuex'
systemDictId: null,  //数据类型  null, 0 ,都试过
 computed: {
      ...mapGetters({
        systemDictId: 'getSystemDictId'
      })
    },
 
// dictValue 中的get List方法
 getDictValueListById () {
        this.axios.get(this.$http.httpUrl('/api/dictValue/selectByDictId'), {
          params: {
            pageNumber: this.currentPage,
            pageSize: this.pageSize,
            systemDictId: this.systemDictId,
          }
        }).then(response => {
          //this.loading = true
          this.dataList = response.data.data.dataList
          this.totalCount = response.data.data.total
        })
      }
java后端:
@GetMapping("selectByDictId")
    public Result<PageInfo<SystemDictValue>> selectByDictId(PageParam pageParam, SystemDictValue systemDictValue) {
        LambdaQueryWrapper<SystemDictValue> queryWrapper = Wrappers.<SystemDictValue>lambdaQuery()
                .eq(SystemDictValue::getSystemDictId, systemDictValue.getSystemDictId());
        return Result.success(systemDictValueService.selectPage(pageParam, queryWrapper));
    }

调试结果
Field error in object 'systemDictValue' on field 'systemDictId': rejected value [NaN]; codes [typeMismatch.systemDictValue.systemDictId,typeMismatch.systemDictId,typeMismatch.java.lang.Integer,typeMismatch]; arguments [org.springframework.context.support.DefaultMessageSourceResolvable: codes [systemDictValue.systemDictId,systemDictId]; arguments []; default message [systemDictId]]; default message [Failed to convert property value of type 'java.lang.String' to required type 'java.lang.Integer' for property 'systemDictId'; nested exception is java.lang.NumberFormatException: For input string: "NaN"]

前端结果:
状态码200,负载显示传递参数NaN

学习阶段,不是特别懂别喷,最好能远程帮忙看看。

收起

  • 写回答

5条回答 默认 最新

  • H3T 2023-04-15 12:58
    关注

    数据类型转换有问题:systemDictId 应该是一个整数类型,但是在传递过程中,它被转换成了字符串类型,并且其值是 NaN。
    前端代码看到item.id 是一个数值类型,但是从后端看SystemDictValue 实体类中的 systemDictId 属性类型不确定,可能是字符串类型或者其他类型,在转换成整数类型时会出现错误。
     
    可以在前端代码中对传递的参数进行类型转换,用 parseInt() 函数将字符串类型的参数转换成整数类型。
    比如:

    this.$store.dispatch('getSystemDictId', parseInt(item.id))
    

    然后,后端代码中的 SystemDictValue 实体类中的 systemDictId 属性应该声明为整数类型,例如 Integer 或 int,在类型转换时不出错。
     
    如果答案对您有所帮助,望采纳。

    评论

报告相同问题?

问题事件

  • 系统已结题 4月23日
  • 修改了问题 4月16日
  • 赞助了问题酬金15元 4月15日
  • 创建了问题 4月15日

悬赏问题

  • ¥20 如何在 rocky9.4 部署 CDH6.3.2?
  • ¥35 navicat将excel中的数据导入mysql出错
  • ¥15 rt-thread线程切换的问题
  • ¥20 python忆阻器数字识别
  • ¥15 高通uboot 打印ubi init err 22
  • ¥20 PDF元数据中的XMP媒体管理属性
  • ¥15 R语言中lasso回归报错
  • ¥15 网站突然不能访问了,上午还好好的
  • ¥15 有没有dl可以帮弄”我去图书馆”秒选道具和积分
  • ¥15 semrush,SEO,内嵌网站,api