【发布时间】:2020-11-12 12:10:55
【问题描述】:
我正在尝试使用 bootstrap-vue 构建一个输入字段,用户可以在其中输入任何所需的数字,并且应该将其格式化为 3 位的十进制数字。
这是我到目前为止所得到的。 focusOut-Method 会提醒我想要的值,但我不知道如何用它更新表行中的值,因为它是按值调用的。你有什么想法吗?
<template>
<div>
<b-table :items="items" :fields="fields" >
<template v-slot:cell(price)="row">
<b-form-input
v-model="row.item.price"
@blur="focusOut($event, row.item.price)"
/>
</template>
</b-table>
</div>
</template>
<script>
export default {
data: function () {
return {
fields: [...],
};
},
computed: {
items: function () {
return [{price: 3.9}, {price: 5}, {price: 9.333}];
},
},
methods: {
focusOut: function (event, value) {
if (["Arrow", "Backspace", "Shift"].includes(event.key)) {
this.preventNextIteration = true;
return;
}
if (this.preventNextIteration) {
this.preventNextIteration = false;
return;
}
value = parseFloat(value.replace(",", ".")).toLocaleString(undefined, {
minimumFractionDigits: 3,
});
alert(value);
},
} ....
};
</script>
【问题讨论】:
标签: vue.js vuejs2 bootstrap-vue