【发布时间】:2020-03-18 12:46:52
【问题描述】:
我有一个 MyList.vue,它直接由我的 app.vue 导入。 MyList.vue 不包含子组件,它只导入:
import store from "../store/store";
import { USER_FETCHLIST } from "../store/actions/user";
数据看起来像这样:
export default {
data () {
return {
tableData: [],
tableheader: []
}
},
created: function(){
store.dispatch(USER_FETCHLIST).then((res) => {
this.tableData = res["data"]["tableData"]
this.tableHeader = res["data"]["tableHeader"]
})
},
methods: {
changeRecord: function(element){
console.log(element)
}
}
}
MyList.vue 具有以下用于 bootstrap-vue 模式的标记:
<template v-for="(element, index) in tableData">
<tr>
//rest of the markup generating the columns carrying the data
<td>
<button v-on:click="changeRecord(element)" v-b-modal="`modal-${index}`">Aendern</button>
<b-modal :id="'modal-' + index" title="BootstrapVue">
<template v-for="(value, name) in element">
<template v-if="typeof value==='object'">
<template v-for="(nestedValue, nestedName) in value">
<span>{{nestedName}}</span>
<input type="text" :value="nestedValue" :class="'editFieldDivision-' + index">
</template>
</template>
<template v-else>
<span>{{name}}</span>
<input type="text" :value="value" :class="'editFieldDivision-' + index">
</template>
</template>
</b-modal>
</td>
</tr>
</template>
点击按钮的结果是这个对话框:
对话框可能有更多或更少的输入字段,具体取决于它从后端接收的数据。
然而,这个对话框应该允许用户从后台的列表中应用更改到相应的记录。 由于我对 vue 很陌生,我不知道“抓取”用户输入的“vue 方法”是什么。我应该使用 v-model 吗?如果是这样,我该怎么做,因为插入的数据/可观察对象是动态插入的。最后将数据放入一维中,其中key-value以各自输入域的“标签”为key,以各自输入域的值为值。
此外,如果用户放弃对话框,则对话框内的更改不应应用于前端的数据集。
【问题讨论】:
标签: javascript vue.js