element ui 在表格中使用el-input-number计数器遇到的坑
添加商品时按钮只能点击一次,编辑时又可以多次点击
原因:表格data中数据specifications中的值没有在vue data()里声明,vue无法拦截监听该属性,因此点击按钮时页面并没有发生改变
使用this.$set()来给specifications中值添加属性的同时,也对该值进行了defineProperty
- 对象操作:
三个参数:this.$set(“改变的对象”,“改变的对象属性”,“值”)
- 数组操作:
三个参数:this.$set(“数组”,“下标”,“值”)
<el-table
ref="multipleTable"
:data="formValidate.specifications"
tooltip-effect="dark"
style="width: 100%"
@selection-change="handleSelectionChange">
<el-table-column label="拼团价" min-width="160">
<template slot-scope="scope">
<el-input-number size="small" v-model="scope.row.group_price" :min="0" :max="scope.row.commodity_price"
:precision="2" :step="0.1" ></el-input-number>
</template>
</el-table-column>
</el-table>
_this.formValidate.specifications.forEach((item) => {
_this.$set(item, 'group_price', 0)
_this.$set(item, 'limit_repertory', 0)
})
export default {
data() {
return {
formValidate: {
specifications: []
}
}
}