admin管理员组

文章数量:1531659

config->index.js->dev->proxyTable{}

修改proxyTable{}为:

proxyTable: {
      '/api': {//虚拟目录
        target: 'http://localhost:8081',//后台NodeSpringboot项目的请求网址
        changeOrigin: true,
        pathRewrite: {
          '^/api': ''//由于上面的虚拟目录实际上是不存在的,不去掉的话访问的时候显示的url会变成'http://localhost:3000/api',所以得去掉
        }
      }
    }

发送ajax请求:

先安装axios命令:npm install axios

<template>
  <div class="hello">
    <div>
      {{title}}
    </div>
    <hr>
    <button @click="convert">点击获取数据</button>
  </div>
</template>

<script>
  import axios from 'axios'

  export default {
    name: 'HelloWorld',
    data() {
      return {
        title: "静态数据"
      }
    },
    methods: {
      convert: function () {
        //这里需要注意一下:域名和端口换成api
        axios.get("api/sysUser/getSomething").then(res => {
          this.title = res.data;
        })
      }
    }
  }
</script>

SpringBoot后台:

  @GetMapping("/getSomething")
    public String getSomething() {
        return "后台数据";
    }

本文标签: vue