Vue3+vite+axios+.net api 配置

export default defineConfig({
  plugins: [vue()],
  resolve: {
    alias: {
      "@": fileURLToPath(new URL("./src", import.meta.url)),
    },
  },
  server: {
    host: "0.0.0.0",
    open: true, //启动项目自动弹出浏览器
    port: "3000",
    proxy: {
      "/api": {
        target: "http://localhost:5186",
        changeOrigin: true,
        rewrite: (path) => path.replace(/^\/api/, ""), // 不可以省略rewrite
      },
    },
  },
});

vite.config.js 配置

import axios from "axios";
const http = axios.create({
  baseURL: "/api",
  timeout: 10000, // 请求超时时间
});
const params = {
  id: 123,
};
const aa = {
  myProperty: "23232",
};
http.post("/api/Values", aa);
http.get("/api/Values", { params });

vue

 [Route("api/[controller]")]
 [ApiController]
 public class ValuesController : ControllerBase
 {
    
     // GET api/<ValuesController>/5
     [HttpPost]
     public string dssss([FromBody] aa id)
     {
         return id.MyProperty;
     }
     [HttpGet]
     public string sdsd(string id)
     {
         return id;
     }

     public class aa
     {
         public string MyProperty { get; set; }
     }

     
 }

接口代码

posted @ 2024-08-12 15:16  ZooooZ  阅读(57)  评论(0)    收藏  举报