使用引导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
},
答案 0 :(得分:0)
可能是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>