跨域问题 —— 前端解决方案

使用请点击:后端跨域

前端解决 

const { defineConfig } = require('@vue/cli-service')
module.exports = defineConfig({
  transpileDependencies: true,
  devServer:{
    proxy:{
      'api':{
        target: 'http://iwenwiki.com',
        changeOrigin:true
      }
    }
  }
})

<template>
  <div>
    <h3>针对前端跨域解决方案</h3>
    <h3>统一访问https://www.axios-http.cn/docs/post_example</h3>
    <p>注意下面的地址,https://www.axios-http.cn 这部分在vue.config.js中配置,所以省略</p>
  </div>
</template>

<script>
import axios from "axios"
export default {
  mounted() {
   axios.get("/api/FingerUnion/list.php").then((res) => {
      console.log(res.data);
    });
  },
};
</script>

<style></style>

<template>
  <cros_demo></cros_demo>
</template>

<script>
import cros_demo from './components/cros_demo.vue'


export default {
  name: 'App',
  components: {
    cros_demo,
  },
  data(){
    return{
        title:"数据传递标题",
        age:20,
        names:["iren","maike"],
        zi_to_fu_text:""
    }
  },
  methods:{
    
  }   
}
</script>

<style scoped>

</style>

 

猜你喜欢

转载自blog.csdn.net/qq_45947664/article/details/127653668