我正在尝试按通过 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);});
关于javascript - 将数据 json 字符串传递给数字 Vue.js,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/61429189/