V2EX = way to explore
V2EX 是一个关于分享和探索的地方
现在注册
已注册用户请  登录
drzhaug
V2EX  ›  Node.js

求问为什么 vue-cli 全局函数的回调函数不生效?

  •  
  •   drzhaug · 2017-06-27 15:15:34 +08:00 · 3151 次点击
    这是一个创建于 2492 天前的主题,其中的信息可能已经有所发展或是发生改变。
    入口文件 main.js 中

    /** 全局请求方法 **/
    Vue.prototype.$request = function(method, url, params = null, callbackfunc){
    var data = {};
    if(params != null) {
    data = params;
    }
    this.$axios({
    method:method,
    url:url,
    data:data,
    }).then(function(res){
    callbackfunc(res)
    })
    .catch(function(err){

    });
    }

    组件中

    mounted: function(){
    this.$request('POST', '/api/api1/account/check', null, function(res){
    console(res.data.code);
    if(res.data.code == '700003') {
    this.router.push({ path: '/home'});
    }

    })
    }

    不回调的话,一切正常。。希望大神指正
    2 条回复    2017-06-28 11:13:08 +08:00
    siteshen
        1
    siteshen  
       2017-06-28 01:25:03 +08:00
    打开下浏览器控制台,也许会发现这个:

    Uncaught TypeError: console is not a function
    drzhaug
        2
    drzhaug  
    OP
       2017-06-28 11:13:08 +08:00
    @siteshen 多谢,见笑了
    关于   ·   帮助文档   ·   博客   ·   API   ·   FAQ   ·   我们的愿景   ·   实用小工具   ·   1046 人在线   最高记录 6543   ·     Select Language
    创意工作者们的社区
    World is powered by solitude
    VERSION: 3.9.8.5 · 24ms · UTC 22:28 · PVG 06:28 · LAX 15:28 · JFK 18:28
    Developed with CodeLauncher
    ♥ Do have faith in what you're doing.