M
M
Michael2017-08-08 14:28:29
Vue.js
Michael, 2017-08-08 14:28:29

Why is vue js props data not updating?

The data is received by ajax request when the button is clicked.
//Button

<button id="show-modal"
    class="P2CL3TInfo"
     v-bind:name="selecId = item.id"
    @click="open()">
</button>

 <modal v-if="showModal" @close="showModal = false"
    :country="mod[0].country"
    :city="mod[0].city"
    :dt="mod[0].created" >
</modal>

//Компонент
Vue.component('modal', {
    props: ['country', 'city', 'vendor', 'dt'],
    data: function () {
      return {
      }
    },
    delimiters: ['${', '}'],
    template: '#modal-template',
//Ajax запрос
            open: function(){
                      axios.get("{% url 'url' %}",{
                          headers: {
                              'X-Requested-With': 'XMLHttpRequest'
                          },
                          params: {
                              id: this.selecId
                          }}).then((response) => {
                              this.$data.mod =  response.data
                              this.showModal = true
                          }).catch(function (error) {
                                  this.selected = error;
                              });
                  },

Why is the data not updated when the window is shown?

Answer the question

In order to leave comments, you need to log in

2 answer(s)
I
Igor Koch, 2017-08-08
@amux

Because this does not pass into the axios object, initialize the variable to be a reference to this.

A
Alexey Shashenkov, 2017-08-08
@teknik2008

this.$data.mod = response.data- so it is not necessary About set and $set

Didn't find what you were looking for?

Ask your question

Ask a Question

731 491 924 answers to any question