Bootstrap Vue - Passing Card Data as a payload

2019-08-22 05:54发布

Is there a similar way to pass card data like rowData when using bootstrap vue?

I am using this function to commit card data to the state and it doesn't seem to work. I am using a similar method to pass rowData and it works fine.

CARD DATA

Action...

setCard: function ({commit}, cardData) {
  commit('setCardToState', cardData)
}

Mutation...

setCardToState (state, cardData) {
  state.addeditinitiative.name = cardData.name
  state.addeditinitiative.description = cardData.description
  state.addeditinitiative.id = cardData.id
},

Template

<b-card v-for="initiative in initiatives" v-b-modal.NewInitiativeModal @click="setCard">
        {{initiative.name}}
      </b-card>

ROW DATA

Template

<b-table striped
             hover
             responsive
             :items="products"
             :fields="fields"
             :filter="reportFilter"
             :current-page="currentPage"
             :per-page="10"
             v-b-modal.EditProductModal
             @row-clicked="setRow"></b-table>
  </b-row>

Action

 setRow: function ({commit}, rowData) {
  commit('setRowToState', rowData)
},

Mutation

setRowToState (state, rowData) {
  state.addeditproduct.name = rowData.name
  state.addeditproduct.productline = rowData.productline
  state.addeditproduct.description = rowData.description
  state.addeditproduct.externalid = rowData.externalid
  state.addeditproduct.active = rowData.active
  state.addeditproduct.id = rowData.id
},

1条回答
▲ chillily
2楼-- · 2019-08-22 06:13

It might be Vue reactivity problem. You can use deepCopy (ex: JSON.parse(JSON.stringify()) to make it reactive

setCardToState (state, cardData) {
  state.addeditinitiative.name = cardData.name
  state.addeditinitiative.description = cardData.description
  state.addeditinitiative.id = cardData.id
  state.addeditinitiative = JSON.parse(JSON.stringify(state.addeditinitiative))
}

Btw, you should add :key when using v-for

<b-card v-for="(initiative, index) in initiatives" :key="index" v-b-modal.NewInitiativeModal @click="setCard">
        {{initiative.name}}
</b-card>
查看更多
登录 后发表回答