[英]Pass data json string to number 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
function 应用于数组并使用Number()
object 构造函数将该属性转换为数字:
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);});
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.