Passing headers with axios POST request

后端 未结 9 1906
青春惊慌失措
青春惊慌失措 2020-11-28 20:27

I have written an axios POST request as recommended from the npm package documentation like:

var data = {
    \'key1\': \'val1\',
    \'key2\': \'val2\'
}
ax         


        
9条回答
  •  没有蜡笔的小新
    2020-11-28 20:54

    Or, if you are using some property from vuejs prototype that can't be read on creation you can also define headers and write i.e.

    storePropertyMaxSpeed(){
                    axios.post('api/property', {
                        "property_name" : 'max_speed',
                        "property_amount" : this.newPropertyMaxSpeed
                        },
                        {headers :  {'Content-Type': 'application/json',
                                    'Authorization': 'Bearer ' + this.$gate.token()}})
                      .then(() => { //this below peace of code isn't important 
                        Event.$emit('dbPropertyChanged');
    
                        $('#addPropertyMaxSpeedModal').modal('hide');
    
                        Swal.fire({
                            position: 'center',
                            type: 'success',
                            title: 'Nova brzina unešena u bazu',
                            showConfirmButton: false,
                            timer: 1500
                            })
                    })
                    .catch(() => {
                         Swal.fire("Neuspješno!", "Nešto je pošlo do đavola", "warning");
                    })
                }
            },
    

提交回复
热议问题