javascript - 创建表后如何立即更新 Vue.js 中的 UI
问题描述
我有一个简单的组件,它调用数据库、检索表列表并在用户单击按钮时创建一个新表。我的功能目前有效,唯一的问题是我必须重新加载页面才能查看更新表的列表,并且我希望新创建的表在用户创建后立即显示,我该如何实现?这是我的尝试:
<md-button class="view-captable-btn" v-for="item in capTables" :key="item.contractAddress">
<p>{{item.label}}</p>
<p class="contract-address-p"> {{item.contractAddress}}</p>
</md-button>
<md-dialog-actions>
<md-button class="close-btn" @click="showDialog = false"><span class="close-btn-span">Cancel</span></md-button>
<md-button class="create-cap-table-btn" @click="showDialog = false; createNewCapTable()"><span class="add-captable-span">Add new cap table</span></md-button>
</md-dialog-actions>
data() {
const apiKey = process.env.VUE_APP_API_ADMIN_KEY;
return {
showDialog: false,
createNewShareholderDialog: false,
services: new this.$service(apiKey),
capTables: null,
initialPoolOptions: ''
}
},
methods: {
async createNewCapTable() {
let label = this.$refs.form.platformName.value
let poolSize = this.$refs.form.poolSize.value
let res = await this.services.deployStockCapTable('http://vue.js', poolSize, label)
console.log(res)
},
logout() {
this.$router.push('/')
},
async readDeployedCapTables() {
let res = await this.services.readAllStockCapTables();
this.capTables = res
},
},
mounted() {
this.readDeployedCapTables()
},
created() {
document.body.style.background = '#e5e5e5';
},
beforeDestroy() {
document.body.style.background = 'white';
},
}
解决方案
您只需要将ie推res
入源代码v-for
capTables
async createNewCapTable() {
let label = this.$refs.form.platformName.value
let poolSize = this.$refs.form.poolSize.value
let res = await this.services.deployStockCapTable('http://vue.js', poolSize, label)
console.log(res)
this.capTables.push(res) // <- this line
},
推荐阅读
- postgresql - Postgres n_tup_ins 与从未分析过的表的行数不匹配
- python - 如何在一个函数调用中按块加密和解密?
- kotlin - 使用 Jetpack Compose 导航
- flutter - 使用前一个小部件的索引值
- android - Android Gradle 读取风味文件
- string - AWS Cloudformation 属性 SubnetIds 的值必须是字符串列表类型
- python - 使用 pyinstaller 时无法加载本机模块“Crypto.Cipher._raw_ecb”
- typescript - 有没有办法指定泛型函数的基本类型?
- oracle - 我无法将我的 sql 连接到 oracle xe 侦听器 ora 错误
- c++ - 堆栈中的 peek() 和 top() 函数有什么区别?