vue3配置代理實(shí)現(xiàn)axios請求本地接口返回PG庫數(shù)據(jù)
前端編寫
安裝 axios
如果當(dāng)前未安裝axios,可以執(zhí)行如下指令安裝
npm install axios
配置代理
當(dāng)前為基于Vite構(gòu)建的項(xiàng)目,在 vite.config.ts 中配置代理,在defineConfig中新增server配置,主要關(guān)注兩個(gè)點(diǎn):
一、需要代理的url開頭,此處為/asset
二、代理的目標(biāo)IP以及端口號,此處為http://localhost:8888
// vite.config.ts
import { defineConfig } from 'vite';
import vue from '@vitejs/plugin-vue';
export default defineConfig({
plugins: [vue()],
server: {
proxy: {
'/asset': { // 以 '/asset' 開頭的請求會被代理
target: 'http://localhost:8888', // 后端服務(wù)器地址
changeOrigin: true, // 允許跨域
rewrite: (path) => path.replace(/^\/asset/, '') // 重寫路徑,去掉 '/asset'
}
}
}
});
如果你的項(xiàng)目基于Vue CLI構(gòu)建,可在vue.config.js添加
// vue.config.js
const { defineConfig } = require('@vue/cli-service');
???????module.exports = defineConfig({
devServer: {
proxy: {
'/asset': { // 以 '/asset' 開頭的請求會被代理
target: 'http://localhost:8888', // 后端服務(wù)器地址
changeOrigin: true, // 允許跨域
pathRewrite: {
'^/asset': '' // 重寫路徑,去掉 '/asset'
}
}
}
}
});前端代碼編寫
此處使用ts&vue3寫法,由于使用原生axios寫法,沒有封裝通用的請求js(后續(xù)博客完善),導(dǎo)致此處解析響應(yīng)會比較繞
const assetInfoList = result?.data?.data?.assetInfoList
<script setup lang="ts">
import { ref } from 'vue'
import axios from 'axios'
const isUseLocalFlag = ref(true)
const setTabData = async function () {
if (isUseLocalFlag.value) {
const bizId = '0777c40218114c35a29b0d4d84355668'
await axios.post(`/asset/assetInfo/${bizId}/byBizId`).then(result => {
if (result.status === 200) {
const assetInfoList = result?.data?.data?.assetInfoList
console.log('assetInfoList', assetInfoList)
}
})
} else {
// 請求mock數(shù)據(jù)
}
}
</script>
<template>
<div>
數(shù)據(jù)源選擇:
</div>
<el-switch
v-model="isUseLocalFlag"
active-text="使用本地服務(wù)數(shù)據(jù)"
inactive-text="使用mock數(shù)據(jù)"
/>
<el-button @click="setTabData" style="margin-left: 10px;">給tab賦值</el-button>
</template>
<style scoped>
</style>后端編寫
pgsql建表&測試數(shù)據(jù)填充
-- 資產(chǎn)信息表創(chuàng)建
CREATE TABLE IF NOT EXISTS t_asset_info (
asset_number varchar(100) COLLATE pg_catalog.default NOT NULL,
asset_status varchar(10) COLLATE pg_catalog.default,
use_dept_code varchar(100) COLLATE pg_catalog.default,
create_time timestamp(0),
create_by_uuid varchar(32) COLLATE pg_catalog.default,
create_by_account varchar(32) COLLATE pg_catalog.default,
create_by_name varchar(100) COLLATE pg_catalog.default,
last_update_time timestamp(0),
last_update_uuid varchar(32) COLLATE pg_catalog.default,
last_update_account varchar(32) COLLATE pg_catalog.default,
last_update_name varchar(100) COLLATE pg_catalog.default,
ext_attribute1 varchar(255) COLLATE pg_catalog.default,
ext_attribute2 varchar(255) COLLATE pg_catalog.default,
ext_attribute3 varchar(255) COLLATE pg_catalog.default,
ext_attribute4 varchar(255) COLLATE pg_catalog.default,
ext_attribute5 varchar(255) COLLATE pg_catalog.default,
ext_attribute6 varchar(255) COLLATE pg_catalog.default,
ext_attribute7 varchar(255) COLLATE pg_catalog.default,
ext_attribute8 varchar(255) COLLATE pg_catalog.default,
ext_attribute9 varchar(255) COLLATE pg_catalog.default,
ext_attribute10 varchar(255) COLLATE pg_catalog.default,
ext_attribute11 varchar(255) COLLATE pg_catalog.default,
ext_attribute12 varchar(255) COLLATE pg_catalog.default,
ext_attribute13 varchar(255) COLLATE pg_catalog.default,
ext_attribute14 varchar(255) COLLATE pg_catalog.default,
ext_attribute15 varchar(255) COLLATE pg_catalog.default,
ext_attribute16 varchar(255) COLLATE pg_catalog.default,
ext_attribute17 varchar(255) COLLATE pg_catalog.default,
ext_attribute18 varchar(255) COLLATE pg_catalog.default,
ext_attribute19 varchar(255) COLLATE pg_catalog.default,
ext_attribute20 varchar(255) COLLATE pg_catalog.default,
biz_id varchar(32) COLLATE pg_catalog.default DEFAULT ''::character varying,
CONSTRAINT asset_info_pkey PRIMARY KEY (asset_number)
)
;
ALTER TABLE t_asset_info
OWNER TO postgres;
COMMENT ON COLUMN t_asset_info.asset_number IS '資產(chǎn)編號';
COMMENT ON COLUMN t_asset_info.asset_status IS '資產(chǎn)狀態(tài)
10:正常
20:使用
30:閑置
40:報(bào)廢
50:封存
60:盤點(diǎn)中
70:在途';
COMMENT ON COLUMN t_asset_info.use_dept_code IS '使用部門名稱';
COMMENT ON COLUMN t_asset_info.create_time IS '創(chuàng)建時(shí)間';
COMMENT ON COLUMN t_asset_info.create_by_uuid IS '創(chuàng)建人uuid';
COMMENT ON COLUMN t_asset_info.create_by_account IS '創(chuàng)建人賬號';
COMMENT ON COLUMN t_asset_info.create_by_name IS '創(chuàng)建人名稱';
COMMENT ON COLUMN t_asset_info.last_update_time IS '最后更新時(shí)間';
COMMENT ON COLUMN t_asset_info.last_update_uuid IS '最后跟新人uuid';
COMMENT ON COLUMN t_asset_info.last_update_account IS '最后更新人賬號';
COMMENT ON COLUMN t_asset_info.last_update_name IS '最后更新人名稱';
COMMENT ON COLUMN t_asset_info.ext_attribute1 IS '拓展屬性1';
COMMENT ON COLUMN t_asset_info.ext_attribute2 IS '拓展屬性2';
COMMENT ON COLUMN t_asset_info.ext_attribute3 IS '拓展屬性3';
COMMENT ON COLUMN t_asset_info.ext_attribute4 IS '拓展屬性4';
COMMENT ON COLUMN t_asset_info.ext_attribute5 IS '拓展屬性5';
COMMENT ON COLUMN t_asset_info.ext_attribute6 IS '拓展屬性6';
COMMENT ON COLUMN t_asset_info.ext_attribute7 IS '拓展屬性7';
COMMENT ON COLUMN t_asset_info.ext_attribute8 IS '拓展屬性8';
COMMENT ON COLUMN t_asset_info.ext_attribute9 IS '拓展屬性9';
COMMENT ON COLUMN t_asset_info.ext_attribute10 IS '拓展屬性10';
COMMENT ON COLUMN t_asset_info.ext_attribute11 IS '拓展屬性11';
COMMENT ON COLUMN t_asset_info.ext_attribute12 IS '拓展屬性12';
COMMENT ON COLUMN t_asset_info.ext_attribute13 IS '拓展屬性13';
COMMENT ON COLUMN t_asset_info.ext_attribute14 IS '拓展屬性14';
COMMENT ON COLUMN t_asset_info.ext_attribute15 IS '拓展屬性15';
COMMENT ON COLUMN t_asset_info.ext_attribute16 IS '拓展屬性16';
COMMENT ON COLUMN t_asset_info.ext_attribute17 IS '拓展屬性17';
COMMENT ON COLUMN t_asset_info.ext_attribute18 IS '拓展屬性18';
COMMENT ON COLUMN t_asset_info.ext_attribute19 IS '拓展屬性19';
COMMENT ON COLUMN t_asset_info.ext_attribute20 IS '拓展屬性20';
COMMENT ON COLUMN t_asset_info.biz_id IS '業(yè)務(wù)ID';
COMMENT ON TABLE t_asset_info IS '資產(chǎn)信息表';
-- 資產(chǎn)信息表插入測試數(shù)據(jù)
INSERT INTO t_asset_info (asset_number, asset_status, use_dept_code, create_time, create_by_uuid, create_by_account, create_by_name, last_update_time, last_update_uuid, last_update_account, last_update_name, ext_attribute1, ext_attribute2, ext_attribute3, ext_attribute4, ext_attribute5, ext_attribute6, ext_attribute7, ext_attribute8, ext_attribute9, ext_attribute10, ext_attribute11, ext_attribute12, ext_attribute13, ext_attribute14, ext_attribute15, ext_attribute16, ext_attribute17, ext_attribute18, ext_attribute19, ext_attribute20, biz_id) VALUES ('03f7744cb08fbf23c5e3a49038b741d9', '60', '00-dept-34', '2025-02-16 21:55:22', 'pine_tree_uuid', 'pine_tree_account', 'pine_tree_name', '2025-02-17 22:29:29', 'pine_tree_uuid', 'pine_tree_account', 'pine_tree_name', 'ext_attribute1', 'ext_attribute2', 'ext_attribute3', 'ext_attribute4', 'ext_attribute5', 'ext_attribute6', 'ext_attribute7', 'ext_attribute8', 'ext_attribute9', 'ext_attribute10', 'ext_attribute11', 'ext_attribute12', 'ext_attribute13', 'ext_attribute14', 'ext_attribute15', 'ext_attribute16', 'ext_attribute17', 'ext_attribute18', 'ext_attribute19', 'ext_attribute20', '0777c40218114c35a29b0d4d84355668');
INSERT INTO t_asset_info (asset_number, asset_status, use_dept_code, create_time, create_by_uuid, create_by_account, create_by_name, last_update_time, last_update_uuid, last_update_account, last_update_name, ext_attribute1, ext_attribute2, ext_attribute3, ext_attribute4, ext_attribute5, ext_attribute6, ext_attribute7, ext_attribute8, ext_attribute9, ext_attribute10, ext_attribute11, ext_attribute12, ext_attribute13, ext_attribute14, ext_attribute15, ext_attribute16, ext_attribute17, ext_attribute18, ext_attribute19, ext_attribute20, biz_id) VALUES ('0777c40218114c35a29b0d4d8435520e', '10', '00-dept-36', '2025-02-16 21:55:22', 'pine_tree_uuid', 'pine_tree_account', 'pine_tree_name', '2025-02-17 22:29:29', 'pine_tree_uuid', 'pine_tree_account', 'pine_tree_name', 'ext_attribute1', 'ext_attribute2', 'ext_attribute3', 'ext_attribute4', 'ext_attribute5', 'ext_attribute6', 'ext_attribute7', 'ext_attribute8', 'ext_attribute9', 'ext_attribute10', 'ext_attribute11', 'ext_attribute12', 'ext_attribute13', 'ext_attribute14', 'ext_attribute15', 'ext_attribute16', 'ext_attribute17', 'ext_attribute18', 'ext_attribute19', 'ext_attribute20', '0777c40218114c35a29b0d4d84355668');
INSERT INTO t_asset_info (asset_number, asset_status, use_dept_code, create_time, create_by_uuid, create_by_account, create_by_name, last_update_time, last_update_uuid, last_update_account, last_update_name, ext_attribute1, ext_attribute2, ext_attribute3, ext_attribute4, ext_attribute5, ext_attribute6, ext_attribute7, ext_attribute8, ext_attribute9, ext_attribute10, ext_attribute11, ext_attribute12, ext_attribute13, ext_attribute14, ext_attribute15, ext_attribute16, ext_attribute17, ext_attribute18, ext_attribute19, ext_attribute20, biz_id) VALUES ('2d72bf99ebcad018297aed761b5dee8d', '10', '00-dept-29', '2025-02-16 21:55:22', 'pine_tree_uuid', 'pine_tree_account', 'pine_tree_name', '2025-02-17 22:29:29', 'pine_tree_uuid', 'pine_tree_account', 'pine_tree_name', 'ext_attribute1', 'ext_attribute2', 'ext_attribute3', 'ext_attribute4', 'ext_attribute5', 'ext_attribute6', 'ext_attribute7', 'ext_attribute8', 'ext_attribute9', 'ext_attribute10', 'ext_attribute11', 'ext_attribute12', 'ext_attribute13', 'ext_attribute14', 'ext_attribute15', 'ext_attribute16', 'ext_attribute17', 'ext_attribute18', 'ext_attribute19', 'ext_attribute20', '0777c40218114c35a29b0d4d84355668');
INSERT INTO t_asset_info (asset_number, asset_status, use_dept_code, create_time, create_by_uuid, create_by_account, create_by_name, last_update_time, last_update_uuid, last_update_account, last_update_name, ext_attribute1, ext_attribute2, ext_attribute3, ext_attribute4, ext_attribute5, ext_attribute6, ext_attribute7, ext_attribute8, ext_attribute9, ext_attribute10, ext_attribute11, ext_attribute12, ext_attribute13, ext_attribute14, ext_attribute15, ext_attribute16, ext_attribute17, ext_attribute18, ext_attribute19, ext_attribute20, biz_id) VALUES ('3d4c487a1679c70f61b0aa3dd5a1733a', '60', '00-dept-27', '2025-02-16 21:55:22', 'pine_tree_uuid', 'pine_tree_account', 'pine_tree_name', '2025-02-17 22:29:29', 'pine_tree_uuid', 'pine_tree_account', 'pine_tree_name', 'ext_attribute1', 'ext_attribute2', 'ext_attribute3', 'ext_attribute4', 'ext_attribute5', 'ext_attribute6', 'ext_attribute7', 'ext_attribute8', 'ext_attribute9', 'ext_attribute10', 'ext_attribute11', 'ext_attribute12', 'ext_attribute13', 'ext_attribute14', 'ext_attribute15', 'ext_attribute16', 'ext_attribute17', 'ext_attribute18', 'ext_attribute19', 'ext_attribute20', '0777c40218114c35a29b0d4d84355668');
INSERT INTO t_asset_info (asset_number, asset_status, use_dept_code, create_time, create_by_uuid, create_by_account, create_by_name, last_update_time, last_update_uuid, last_update_account, last_update_name, ext_attribute1, ext_attribute2, ext_attribute3, ext_attribute4, ext_attribute5, ext_attribute6, ext_attribute7, ext_attribute8, ext_attribute9, ext_attribute10, ext_attribute11, ext_attribute12, ext_attribute13, ext_attribute14, ext_attribute15, ext_attribute16, ext_attribute17, ext_attribute18, ext_attribute19, ext_attribute20, biz_id) VALUES ('4f22a0a4fe1a8ccc5916718cd1049241', '70', '00-dept-28', '2025-02-16 21:55:22', 'pine_tree_uuid', 'pine_tree_account', 'pine_tree_name', '2025-02-17 22:29:29', 'pine_tree_uuid', 'pine_tree_account', 'pine_tree_name', 'ext_attribute1', 'ext_attribute2', 'ext_attribute3', 'ext_attribute4', 'ext_attribute5', 'ext_attribute6', 'ext_attribute7', 'ext_attribute8', 'ext_attribute9', 'ext_attribute10', 'ext_attribute11', 'ext_attribute12', 'ext_attribute13', 'ext_attribute14', 'ext_attribute15', 'ext_attribute16', 'ext_attribute17', 'ext_attribute18', 'ext_attribute19', 'ext_attribute20', '0777c40218114c35a29b0d4d84355668');
INSERT INTO t_asset_info (asset_number, asset_status, use_dept_code, create_time, create_by_uuid, create_by_account, create_by_name, last_update_time, last_update_uuid, last_update_account, last_update_name, ext_attribute1, ext_attribute2, ext_attribute3, ext_attribute4, ext_attribute5, ext_attribute6, ext_attribute7, ext_attribute8, ext_attribute9, ext_attribute10, ext_attribute11, ext_attribute12, ext_attribute13, ext_attribute14, ext_attribute15, ext_attribute16, ext_attribute17, ext_attribute18, ext_attribute19, ext_attribute20, biz_id) VALUES ('6ac629baf0e5af838433f7d48751cbbc', '50', '00-dept-33', '2025-02-16 21:55:22', 'pine_tree_uuid', 'pine_tree_account', 'pine_tree_name', '2025-02-17 22:29:29', 'pine_tree_uuid', 'pine_tree_account', 'pine_tree_name', 'ext_attribute1', 'ext_attribute2', 'ext_attribute3', 'ext_attribute4', 'ext_attribute5', 'ext_attribute6', 'ext_attribute7', 'ext_attribute8', 'ext_attribute9', 'ext_attribute10', 'ext_attribute11', 'ext_attribute12', 'ext_attribute13', 'ext_attribute14', 'ext_attribute15', 'ext_attribute16', 'ext_attribute17', 'ext_attribute18', 'ext_attribute19', 'ext_attribute20', '0777c40218114c35a29b0d4d84355668');
INSERT INTO t_asset_info (asset_number, asset_status, use_dept_code, create_time, create_by_uuid, create_by_account, create_by_name, last_update_time, last_update_uuid, last_update_account, last_update_name, ext_attribute1, ext_attribute2, ext_attribute3, ext_attribute4, ext_attribute5, ext_attribute6, ext_attribute7, ext_attribute8, ext_attribute9, ext_attribute10, ext_attribute11, ext_attribute12, ext_attribute13, ext_attribute14, ext_attribute15, ext_attribute16, ext_attribute17, ext_attribute18, ext_attribute19, ext_attribute20, biz_id) VALUES ('7396d84b53bc253123ce149aae367227', '30', '00-dept-31', '2025-02-16 21:55:22', 'pine_tree_uuid', 'pine_tree_account', 'pine_tree_name', '2025-02-17 22:29:29', 'pine_tree_uuid', 'pine_tree_account', 'pine_tree_name', 'ext_attribute1', 'ext_attribute2', 'ext_attribute3', 'ext_attribute4', 'ext_attribute5', 'ext_attribute6', 'ext_attribute7', 'ext_attribute8', 'ext_attribute9', 'ext_attribute10', 'ext_attribute11', 'ext_attribute12', 'ext_attribute13', 'ext_attribute14', 'ext_attribute15', 'ext_attribute16', 'ext_attribute17', 'ext_attribute18', 'ext_attribute19', 'ext_attribute20', '0777c40218114c35a29b0d4d84355668');
INSERT INTO t_asset_info (asset_number, asset_status, use_dept_code, create_time, create_by_uuid, create_by_account, create_by_name, last_update_time, last_update_uuid, last_update_account, last_update_name, ext_attribute1, ext_attribute2, ext_attribute3, ext_attribute4, ext_attribute5, ext_attribute6, ext_attribute7, ext_attribute8, ext_attribute9, ext_attribute10, ext_attribute11, ext_attribute12, ext_attribute13, ext_attribute14, ext_attribute15, ext_attribute16, ext_attribute17, ext_attribute18, ext_attribute19, ext_attribute20, biz_id) VALUES ('74fd3149eb6b63b4a05974644b12b9f7', '20', '00-dept-30', '2025-02-16 21:55:22', 'pine_tree_uuid', 'pine_tree_account', 'pine_tree_name', '2025-02-17 22:29:29', 'pine_tree_uuid', 'pine_tree_account', 'pine_tree_name', 'ext_attribute1', 'ext_attribute2', 'ext_attribute3', 'ext_attribute4', 'ext_attribute5', 'ext_attribute6', 'ext_attribute7', 'ext_attribute8', 'ext_attribute9', 'ext_attribute10', 'ext_attribute11', 'ext_attribute12', 'ext_attribute13', 'ext_attribute14', 'ext_attribute15', 'ext_attribute16', 'ext_attribute17', 'ext_attribute18', 'ext_attribute19', 'ext_attribute20', '0777c40218114c35a29b0d4d84355668');
INSERT INTO t_asset_info (asset_number, asset_status, use_dept_code, create_time, create_by_uuid, create_by_account, create_by_name, last_update_time, last_update_uuid, last_update_account, last_update_name, ext_attribute1, ext_attribute2, ext_attribute3, ext_attribute4, ext_attribute5, ext_attribute6, ext_attribute7, ext_attribute8, ext_attribute9, ext_attribute10, ext_attribute11, ext_attribute12, ext_attribute13, ext_attribute14, ext_attribute15, ext_attribute16, ext_attribute17, ext_attribute18, ext_attribute19, ext_attribute20, biz_id) VALUES ('a33fa6930899ca9b30ff93a95dedd11e', '70', '00-dept-35', '2025-02-16 21:55:22', 'pine_tree_uuid', 'pine_tree_account', 'pine_tree_name', '2025-02-17 22:29:29', 'pine_tree_uuid', 'pine_tree_account', 'pine_tree_name', 'ext_attribute1', 'ext_attribute2', 'ext_attribute3', 'ext_attribute4', 'ext_attribute5', 'ext_attribute6', 'ext_attribute7', 'ext_attribute8', 'ext_attribute9', 'ext_attribute10', 'ext_attribute11', 'ext_attribute12', 'ext_attribute13', 'ext_attribute14', 'ext_attribute15', 'ext_attribute16', 'ext_attribute17', 'ext_attribute18', 'ext_attribute19', 'ext_attribute20', '0777c40218114c35a29b0d4d84355668');
INSERT INTO t_asset_info (asset_number, asset_status, use_dept_code, create_time, create_by_uuid, create_by_account, create_by_name, last_update_time, last_update_uuid, last_update_account, last_update_name, ext_attribute1, ext_attribute2, ext_attribute3, ext_attribute4, ext_attribute5, ext_attribute6, ext_attribute7, ext_attribute8, ext_attribute9, ext_attribute10, ext_attribute11, ext_attribute12, ext_attribute13, ext_attribute14, ext_attribute15, ext_attribute16, ext_attribute17, ext_attribute18, ext_attribute19, ext_attribute20, biz_id) VALUES ('db06878e60b8db82c4412d11ff793d18', '40', '00-dept-32', '2025-02-16 21:55:22', 'pine_tree_uuid', 'pine_tree_account', 'pine_tree_name', '2025-02-17 22:29:29', 'pine_tree_uuid', 'pine_tree_account', 'pine_tree_name', 'ext_attribute1', 'ext_attribute2', 'ext_attribute3', 'ext_attribute4', 'ext_attribute5', 'ext_attribute6', 'ext_attribute7', 'ext_attribute8', 'ext_attribute9', 'ext_attribute10', 'ext_attribute11', 'ext_attribute12', 'ext_attribute13', 'ext_attribute14', 'ext_attribute15', 'ext_attribute16', 'ext_attribute17', 'ext_attribute18', 'ext_attribute19', 'ext_attribute20', '0777c40218114c35a29b0d4d84355668');實(shí)體類新增
/**
* <p>
* 資產(chǎn)信息表
* </p>
*
* @author PineTree
* @since 2025-02-16
*/
@TableName("t_asset_info")
@ApiModel(value = "AssetInfo對象", description = "資產(chǎn)信息表")
@Data
public class AssetInfoDTO implements Serializable {
private static final long serialVersionUID = 1L;
@ApiModelProperty("資產(chǎn)編號")
@TableId(value = "asset_number", type = IdType.ASSIGN_UUID)
private String assetNumber;
@ApiModelProperty("資產(chǎn)狀態(tài) 10:正常 20:使用 30:閑置 40:報(bào)廢 50:封存 60:盤點(diǎn)中 70:在途")
private String assetStatus;
@ApiModelProperty("使用部門名稱")
private String useDeptCode;
@ApiModelProperty("創(chuàng)建時(shí)間")
private LocalDateTime createTime;
@ApiModelProperty("創(chuàng)建人uuid")
private String createByUuid;
@ApiModelProperty("創(chuàng)建人賬號")
private String createByAccount;
@ApiModelProperty("創(chuàng)建人名稱")
private String createByName;
@ApiModelProperty("最后更新時(shí)間")
private LocalDateTime lastUpdateTime;
@ApiModelProperty("最后跟新人uuid")
private String lastUpdateUuid;
@ApiModelProperty("最后更新人賬號")
private String lastUpdateAccount;
@ApiModelProperty("最后更新人名稱")
private String lastUpdateName;
@ApiModelProperty("拓展屬性1")
private String extAttribute1;
@ApiModelProperty("拓展屬性2")
private String extAttribute2;
@ApiModelProperty("拓展屬性3")
private String extAttribute3;
@ApiModelProperty("拓展屬性4")
private String extAttribute4;
@ApiModelProperty("拓展屬性5")
private String extAttribute5;
@ApiModelProperty("拓展屬性6")
private String extAttribute6;
@ApiModelProperty("拓展屬性7")
private String extAttribute7;
@ApiModelProperty("拓展屬性8")
private String extAttribute8;
@ApiModelProperty("拓展屬性9")
private String extAttribute9;
@ApiModelProperty("拓展屬性10")
private String extAttribute10;
@ApiModelProperty("拓展屬性11")
private String extAttribute11;
@ApiModelProperty("拓展屬性12")
private String extAttribute12;
@ApiModelProperty("拓展屬性13")
private String extAttribute13;
@ApiModelProperty("拓展屬性14")
private String extAttribute14;
@ApiModelProperty("拓展屬性15")
private String extAttribute15;
@ApiModelProperty("拓展屬性16")
private String extAttribute16;
@ApiModelProperty("拓展屬性17")
private String extAttribute17;
@ApiModelProperty("拓展屬性18")
private String extAttribute18;
@ApiModelProperty("拓展屬性19")
private String extAttribute19;
@ApiModelProperty("拓展屬性20")
private String extAttribute20;
@ApiModelProperty("業(yè)務(wù)ID")
private String bizId;
}controller層代碼編寫
由于使用了mybatis-plus,調(diào)用了通用service查詢邏輯,只需編寫controller即可
/**
* <p>
* 資產(chǎn)信息表 前端控制器
* </p>
*
* @author PineTree
* @since 2025-02-16
*/
@RestController
@RequestMapping("/assetInfo")
public class AssetInfoController {
??????? @Resource
private IAssetInfoService assetInfoService;
@PostMapping("{bizId}/byBizId")
public Result getAssetInfoByBizId(@PathVariable("bizId") String bizId) {
if (StringUtils.isEmpty(bizId)) {
return Result.ok();
}
QueryWrapper<AssetInfoDTO> queryWrapper = new QueryWrapper<>();
queryWrapper.eq("biz_id", bizId);
List<AssetInfoDTO> assetInfoList = assetInfoService.list(queryWrapper);
return Result.ok().data("assetInfoList", assetInfoList);
}
}postMan接口測試
啟動(dòng)本地后端,base_url為api collection維度的全局環(huán)境變量,此處設(shè)置為本地8888端口,可方便后續(xù)切換

聯(lián)調(diào)
點(diǎn)擊tab按鈕,可以觀察到成功從前端5173端口代理到8888并獲取到了響應(yīng)數(shù)據(jù)

到此這篇關(guān)于vue3配置代理實(shí)現(xiàn)axios請求本地接口返回PG庫數(shù)據(jù)的文章就介紹到這了,更多相關(guān)vue3 axios請求本地接口內(nèi)容請搜索腳本之家以前的文章或繼續(xù)瀏覽下面的相關(guān)文章希望大家以后多多支持腳本之家!
相關(guān)文章
基于Vue3實(shí)現(xiàn)鼠標(biāo)滑動(dòng)和滾輪控制的輪播
在這篇文章主要為大家詳細(xì)介紹了如何一步步地實(shí)現(xiàn)一個(gè)基于?Vue?3?的輪播組件,這個(gè)組件的特點(diǎn)是可以通過鼠標(biāo)滑動(dòng)和滾輪來控制輪播圖的切換,感興趣的可以了解下2024-02-02
vue 實(shí)現(xiàn)滾動(dòng)到底部翻頁效果(pc端)
這篇文章主要介紹了pc端vue 滾動(dòng)到底部翻頁效果,本文通過實(shí)例代碼給大家介紹的非常詳細(xì),具有一定的參考借鑒價(jià)值 ,需要的朋友可以參考下2019-07-07
vscode中eslint插件的配置(prettier配置無效)
這篇文章主要介紹了vscode中eslint插件的配置(prettier配置無效),文中通過示例代碼介紹的非常詳細(xì),對大家的學(xué)習(xí)或者工作具有一定的參考學(xué)習(xí)價(jià)值,需要的朋友們下面隨著小編來一起學(xué)習(xí)學(xué)習(xí)吧2019-09-09
vue-cli項(xiàng)目使用vue-picture-preview圖片預(yù)覽組件方式
這篇文章主要介紹了vue-cli項(xiàng)目使用vue-picture-preview圖片預(yù)覽組件方式,具有很好的參考價(jià)值,希望對大家有所幫助。如有錯(cuò)誤或未考慮完全的地方,望不吝賜教2022-09-09
vue/react項(xiàng)目刷新頁面出現(xiàn)404報(bào)錯(cuò)的原因及解決辦法
Vue項(xiàng)目打包部署到線上后,刷新頁面會提示404,下面這篇文章主要給大家介紹了關(guān)于vue/react項(xiàng)目刷新頁面出現(xiàn)404報(bào)錯(cuò)的原因及解決辦法,文中將解決的辦法介紹的很詳細(xì),需要的朋友可以參考下2023-05-05

