S
S
semki0962017-05-19 00:08:16
Vue.js
semki096, 2017-05-19 00:08:16

How to work with server response in vuejs?

Something like this I send a post-request with Ajax, here I get the server response. How can I now place the response in another region of the page in the form of {{response}} ?

new Vue({
        el: "#my_submit",
            methods: {
                send: function(){
                    axios.post('/my_page', json)
        .then(function (response) {
        console.log(response.data.foo);
    })
    .catch(function (error) {
      console.log(error);
    });
                ...

Answer the question

In order to leave comments, you need to log in

1 answer(s)
R
RidgeA, 2017-05-19
@semki096

new Vue({
        el: "#my_submit",
            methods: {
                send: function(){
                    axios.post('/my_page', json)
        .then(function (response) {
        this.somevar = response //<----------------------------------
        console.log(response.data.foo);
    })
    .catch(function (error) {
      console.log(error);
    });
                ...

and somewhere in the component template
Here, in principle, it is written https://vuejs.org/v2/guide/components.html

Didn't find what you were looking for?

Ask your question

Ask a Question

731 491 924 answers to any question