drzhaug
V2EX  ›  Node.js

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

  •  
  •   drzhaug · Jun 27, 2017 · 4059 views
    This topic created in 3277 days ago, the information mentioned may be changed or developed.
    入口文件 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 replies    2017-06-28 11:13:08 +08:00
    siteshen
        1
    siteshen  
       Jun 28, 2017
    打开下浏览器控制台,也许会发现这个:

    Uncaught TypeError: console is not a function
    drzhaug
        2
    drzhaug  
    OP
       Jun 28, 2017
    @siteshen 多谢,见笑了
    About   ·   Help   ·   Advertise   ·   Blog   ·   API   ·   FAQ   ·   Solana   ·   5345 Online   Highest 6679   ·     Select Language
    创意工作者们的社区
    World is powered by solitude
    VERSION: 3.9.8.5 · 41ms · UTC 07:36 · PVG 15:36 · LAX 00:36 · JFK 03:36
    ♥ Do have faith in what you're doing.