vue 前端传参到后台的几种方式
第一种:路径传参js:// 下拉框数据export function getUnits(userId,unitCode) {return request({url: `rfs/ledger/getUnits/${userId}/${unitCode}`,method: 'get'})}往vue组件页面导入js :import {getUnits,resourceSummaryByUnicode}
·
第一种:路径传参
js:
// 下拉框数据
export function getUnits(userId,unitCode) {
return request({
url: `rfs/ledger/getUnits/${userId}/${unitCode}`,
method: 'get'
})
}
往vue组件页面导入js :
import {
getUnits,
resourceSummaryByUnicode
} from '@/api/resource/resource'
发送请求:
getUnits(this.userId, this.unitCode).then((response) => {
console.log(response.data.item)
this.options = response.data.item
this.loading = false
})
第二种:定义params
js:
export function resourceSummaryByUnicode(params) {
return request({
url: `rfs/ledger/resourceSummaryByUnicode`,
method: 'get',
params
})
}
往vue组件页面导入js :
import {
getUnits,
resourceSummaryByUnicode
} from '@/api/resource/resource'
定义请求方法:
getSheet() {
this.loading = true
const val = {
userId: this.userId,
unitCode: this.unitCode
}
resourceSummaryByUnicode(val).then((response) => {
console.log(response.data.item)
this.List = response.data.item
this.loading = false
})
},
更多推荐
已为社区贡献1条内容
所有评论(0)