代码之家  ›  专栏  ›  技术社区  ›  Rehan

axios内的道具值未更新

  •  0
  • Rehan  · 技术社区  · 6 年前

    我有一个 Vue components axios props 因为空的时候试着把它传进来 GET

    var custom_erp_widget = new Vue({
        el : '#custom-erp-widgets',
        data : {
            showContainerHeader : false,
            currentModuleName : 'foo',
            currentModuleFormID : '5',
            currentModuleReportID : '6'
        },
        components : {
            'custom-erp-header' : {
                template : '<div class="col-12" id="custom-erp-widget-header">'+
                            '{{ currentModuleName.toUpperCase() }}'+
                           '</div>',
                props : ['currentModuleName']
            },
            'custom-erp-body' : {
                template : '<div class="col-12" id="custom-erp-widget-body">'+
                           '</div>',
                props : ['currentModuleFormId','currentModuleReportId'],
                // for emitting events so that the child components
                // like (header/body) can catch and act accordingly
                created() {
                    var _this = this;
                    eventHub.$on('getFormData', function(e) {
                        if(e == 'report'){
                            console.log(_this.$props);
    
                            _this.getReportData();
                        }
                        else if(e == 'form'){
                            console.log(_this.$props);
                            _this.getFormData();
                        }
    
                    });
    
                  },
    
                methods : {
                    // function to get the form data from the server
                    // for the requested form
                    getFormData : function(){
                        var _this = this;
                        var x = _this.$props;
                        // here the props are having values
                        //currentModuleFormId: 1
                        //currentModuleReportId: 0
                        console.log(x);
    
                        axios
                            .get('http://localhost:3000/getFormData',{
                                params: {
                                    //here both are '' in the server-side
                                    formID: JSON.stringify(_this.$props) + 'a'
                                }
                            })
                            .then(function(response){
    
                                console.log(response);
    
                            })
                    }
    
                }
    
            }
        },
    
    })
    

    这是真正的街区

    getFormData : function(){
    
        var _this = this;
        var x = _this.$props.currentModuleFormId;
        console.log(x);
        let urs = 'http://localhost:3000/getFormData?formID='+_this.$props.currentModuleFormId.toString();
        axios
            .get(urs , {
                params: {
                  formID: _this.$props.currentModuleFormId
                }
            })
            .then(function(response){
    
                console.log(response);
    
            })
    }
    

    enter image description here

    0 回复  |  直到 6 年前