Tt-wW 2019-09-26 13:21 采纳率: 0%
浏览 879

axios跨域问题,跪求大佬帮忙

axios跨域配置好了,但是点击一点反应都没有,有时候跨域失败,(但是配置没错啊)求大佬帮忙


import axios from 'axios'

Vue.prototype.$axios = axios

axios.defaults.baseURL = '/api'

module.exports = {
    devServer: {
        open: true,
        host: '127.0.0.1',
        port: 8080,
        https: false,
        hotOnly: false,
        proxy: { // 配置跨域
            '/api': {
                target: 'http://localhost:3000',
                ws: true,
                changOrigin: true,
                pathRewrite: {
                    '^/api': ''
                }
            }
        },
        before: app => { }
    }
}







<template>
    <div class="test">
        名字:{user.name}
        年龄: {user.age}
        <input type="submit" @click='submit'>
    </div>
</template>


<script>
export default {
    name : 'test',
    data() {
        return {
            user : []
        }
    },
    methods : {
        submit(){
            this.$axios.get('/api/test').then(result =>{
                console.log(result)
                this.name = result.name
                this.age = result.age
            }).catch(err =>{
                console.log(err)
            })
        }
    }

}
</script>



router.get('/test',(req,res)=>{
    let user ={
        name : 'tw',
        age : 18
    }
    return  res.json(user)
})

点击submit,控制台没一点反应,什么东西都不显示

  • 写回答

3条回答 默认 最新

  • 叶子兔 2019-09-26 14:01
    关注

    你试试把sbumit方法得第一行加上console.log("c成功")应该也不会输出,你是用vue写得代码么?vue得methods不应该是 submit:function(){}这种么?

    评论

报告相同问题?

悬赏问题

  • ¥30 matlab解优化问题代码
  • ¥15 写论文,需要数据支撑
  • ¥15 identifier of an instance of 类 was altered from xx to xx错误
  • ¥100 反编译微信小游戏求指导
  • ¥15 docker模式webrtc-streamer 无法播放公网rtsp
  • ¥15 学不会递归,理解不了汉诺塔参数变化
  • ¥15 基于图神经网络的COVID-19药物筛选研究
  • ¥30 软件自定义无线电该怎样使用
  • ¥15 R语言mediation包做中介分析,直接效应和间接效应都很小,为什么?
  • ¥15 Jenkins+k8s部署slave节点offline