javascript - 每次动作发生时如何让Vue从数据库中获取数据?
问题描述
我在每一行旁边都有一个按钮,每一行在数据库中都有不同的条目。单击该按钮后,我设法获得了希望出现在 Bootstrap 模态中的信息。我仍在努力确保每次点击时 Vue 都会更新。我有以下模态代码:
<tr v-for="click in clicks">
<td><button type="button" @click="returnIndex(click)" class="btn btn-primary" data-toggle="modal" data-target=".bd-example-modal-xl">{{ $t('common.moreDetails') | capitalize }}</button>
<div class="modal fade bd-example-modal-xl" tabindex="-1" role="dialog" aria-labelledby="myLargeModalLabel" aria-hidden="true">
<div class="modal-dialog modal-xl" role="document">
<div class="modal-content">
<div class="modal-body">
<div class="container-fluid">
<div class="row">
<div class="col-md-3">
{{ $t('entity.property1') | capitalize }}
{{ entity.somePropertyName1 }}
</div>
<div class="col-md-3">
{{ $t('entity.property2') | capitalize }}
{{ entity.somePropertyName2 }}
</div>
<div class="col-md-3">
{{ $t('entity.property3') | capitalize }}
{{ entity.somePropertyName3 }}
</div>
<div class="col-md-3">
{{ $t('entity.property4') | capitalize }}
{{ entity.somePropertyName4 }}
</div>
</div>
</div>
<div class="modal-footer">
<button type="button" class="btn btn-secondary" data-dismiss="modal">Close</button>
</div>
</div>
</div>
</div>
</div>
</td>
</tr>
在我的方法中,我有这个:
returnIndex(click) {
return click.status = true;
}
这种方法的灵感来自SO 上的这个答案。但我可能误解了它。目前的情况是,当我单击按钮时,它显示该somePropety
实体的,但是当您单击另一个实体时,它仍然显示相同的属性,而它应该刷新(即获取不同的数据)。
这些是一些图片,以使其清楚:
当值实际上只分配给一个条目时,它会显示test
在我拥有的所有 5000 个条目上。test
它应该为其余部分选择不同的值,但事实并非如此。
编辑:为了清楚起见,test
应该已经在propety1/2/3/4
但还没有设法让它工作,所以请忽略它。
解决方案
模态在您的 v-for... 每次单击时,都会打开所有模态(您只看到最后一个)
做这样的事情: https ://codesandbox.io/s/simple-todo-app-with-vue-gx097
PS:没有 :key ... https://vuejs.org/v2/api/?#key的 v-for 可能会出现渲染问题
推荐阅读
- google-bigquery - 查询查找在bigquery中一个接一个创建的记录
- javascript - 这些 Vue 和手动生成的 html css 元素有什么区别?
- autohotkey - 比较不同目录中的文件名(减去扩展名),如果名称与 AutoHotkey 相同,则复制/移动
- extjs - EXTJS:未捕获的 ReferenceError:Dexie 未在 myJavascriptFile.js:18 中定义
- vue.js - 在 Vue.JS 应用加载时从远程 API 获取数据
- apache - NGINX 不使用 proxy_cache_background_update 提供“快速”陈旧内容
- java - 在我的系统中哪里可以找到 App Engine Maven 插件的当前安装版本?
- regex - 使用嵌套标记扫描具有非定界字符串的语言
- android - notifyDataSetChanged 在自定义 BaseExpandableListAdapter 中不起作用
- google-cloud-platform - 在不知情的情况下注册了 Google Compute Engine