vue路由传参传接口中的一个值,怎样传单独的不是把接口中的这个值全部传过去了?

作者站长头像
站长
· 阅读数 9

只需要接口中的一个code值,想要把这个值传到另一个组件里面作为接口参数传给后端,在home组件中有一个路由跳转到appointment了,我就把这个code值作为路由参数传过去了,这样做合理吗?vue路由传参传接口中的一个值,怎样传单独的不是把接口中的这个值全部传过去了?下面的图是目录结构vue路由传参传接口中的一个值,怎样传单独的不是把接口中的这个值全部传过去了?

院区的接口
async courtyard () {
      const data = await homeCourtyard({channel: 1})
      if (data.state === 1) {
        this.courtyardData = data.data
        this.yqCode = this.courtyardData.map((item) => {
          return item.code
        })
        console.log(this.yqCode)
      } else {
        this.courtyardData = []
      }
    },
typePage () {
      this.$router.push({ path: '/appointment', query: {res: this.yqCode} })
    }

这样传完后,在appointment组件接收后作为接口参数传过去,就变成了三个了

async getDeptCateList () {
      const res = await getDeptCate({channel: 1, scl_id: this.$route.query.res})
      console.log(res)
    }

vue路由传参传接口中的一个值,怎样传单独的不是把接口中的这个值全部传过去了?这样虽然能获取到接口数据,总感觉不对劲,请问我应该怎么修改呢?而且为啥接口传参后scl_id参数名后面会有一个数组,这个应该怎么去掉?三个院区,三个code值vue路由传参传接口中的一个值,怎样传单独的不是把接口中的这个值全部传过去了?home组件传code值vue路由传参传接口中的一个值,怎样传单独的不是把接口中的这个值全部传过去了?appointement组件接收值,作为接口的参数,并把接口赋值给下拉框做渲染vue路由传参传接口中的一个值,怎样传单独的不是把接口中的这个值全部传过去了?

回复
1个回答
avatar
test
2024-06-30
<template>
    <div>
         <div @click="ypePage(0)">总院区</div>
         <div @click="ypePage(1)">东院区</div>
         <div @click="ypePage(2)">医院</div>
    </div>
</template>
ypePage (index) {
  this.$router.push({ path: '/appointment', query: {res: this.yqCode[index]} })
}
回复
likes
适合作为回答的
  • 经过验证的有效解决办法
  • 自己的经验指引,对解决问题有帮助
  • 遵循 Markdown 语法排版,代码语义正确
不该作为回答的
  • 询问内容细节或回复楼层
  • 与题目无关的内容
  • “赞”“顶”“同问”“看手册”“解决了没”等毫无意义的内容