javascript - 将数据 json 字符串传递给数字 Vue.js
问题描述
我正在尝试按数字和通过 API 收集的单词对表格进行排序,单词对它们进行了很好的排序,但数字没有,如何将字符串的值传递给数字。
这是我对 API 的调用。
axios.get(`/json/secciones`+ tienda +`.json`)
.then(response => {this.userInfo = response.data;})
.catch(e => {this.errors.push(e);});
并把它还给我
[
{
"id_store": 2,
"id_section": 1,
"desc_section": "MATERIALES DE CONSTRUCCION",
"id_rule": 1,
"sale_potential": "79413.5525190617"
},
{
"id_store": 2,
"id_section": 2,
"desc_section": "CARPINTERIA Y MADERA",
"id_rule": 1,
"sale_potential": "74704.3439572555"
},
{
"id_store": 2,
"id_section": 3,
"desc_section": "ELECTR-FONTAN-CALOR",
"id_rule": 1,
"sale_potential": "101255.89182774"
},
{
"id_store": 2,
"id_section": 4,
"desc_section": "HERRAMIENTA",
"id_rule": 1,
"sale_potential": "36969.8901028374"
}
]
我怎么能像这样找回它?
[
{
"id_store": 2,
"id_section": 1,
"desc_section": "MATERIALES DE CONSTRUCCION",
"id_rule": 1,
"sale_potential": 79413.5525190617
},
{
"id_store": 2,
"id_section": 2,
"desc_section": "CARPINTERIA Y MADERA",
"id_rule": 1,
"sale_potential": 74704.3439572555
},
{
"id_store": 2,
"id_section": 3,
"desc_section": "ELECTR-FONTAN-CALOR",
"id_rule": 1,
"sale_potential": 101255.89182774
},
{
"id_store": 2,
"id_section": 4,
"desc_section": "HERRAMIENTA",
"id_rule": 1,
"sale_potential": 36969.8901028374
}
]
解决方案
尝试使用map
应用于数组的函数并使用Number()
对象构造函数将该属性转换为数字:
axios.get(`/json/secciones`+ tienda +`.json`)
.then(response => {this.userInfo = response.data.map(item=>{
item.sale_potential=Number(item.sale_potential)
return item;
});
})
.catch(e => {this.errors.push(e);});
推荐阅读
- php - Set-Cookie 缓存,即使使用 F5 ?(除非我按 CTRL+F5)
- android - 在没有 Android 的情况下接收 GCM 通知
- c# - Entity Framework Core 异步更新失败,受影响的行数为 0
- android - setvalue 方法不写入 firebase 数据库
- php - 在 CodeIgniter 中找不到对象
- java - 当 CSVParser 中有记录时,csvParser.getRecords() 返回空
- java - 如何将数据从第 5 个活动发送到第 1 个活动?
- html - 绝对容器中的 CSS flex 布局
- docker - 错误:错误:请求超时-InfluxDB sitespeed.io
- sql-server - 插入 OPENROWSET 错误字符串或二进制数据将被截断