引导Vue公司 - 传递卡数据作为有效载荷(Bootstrap Vue - Passing Card

2019-10-28 21:13发布

有没有类似的方式使用引导VUE时传递卡数据,如rowData?

我使用这个功能来卡数据提交到状态,它似乎并没有工作。 我使用类似的方法来传递rowData并能正常工作。

卡数据

行动...

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

突变...

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

模板

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

行数据

模板

<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>

行动

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

突变

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
},

Answer 1:

这可能是Vue的反应问题。 您可以使用deepcopy的(例如: JSON.parse(JSON.stringify())使其反应

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))
}

顺便说一句,你应该增加:key当使用v-for

<b-card v-for="(initiative, index) in initiatives" :key="index" v-b-modal.NewInitiativeModal @click="setCard">
        {{initiative.name}}
</b-card>


文章来源: Bootstrap Vue - Passing Card Data as a payload