只需要接口中的一个code值,想要把这个值传到另一个组件里面作为接口参数传给后端,在home组件中有一个路由跳转到appointment了,我就把这个code值作为路由参数传过去了,这样做合理吗?
下面的图是目录结构
院区的接口
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)
}
这样虽然能获取到接口数据,总感觉不对劲,请问我应该怎么修改呢?而且为啥接口传参后scl_id参数名后面会有一个数组,这个应该怎么去掉?
三个院区,三个code值
home组件传code值
appointement组件接收值,作为接口的参数,并把接口赋值给下拉框做渲染