Warning: file_get_contents(/data/phpspider/zhask/data//catemap/9/javascript/476.json): failed to open stream: No such file or directory in /data/phpspider/zhask/libs/function.php on line 167

Warning: Invalid argument supplied for foreach() in /data/phpspider/zhask/libs/tag.function.php on line 1116

Notice: Undefined index: in /data/phpspider/zhask/libs/function.php on line 180

Warning: array_chunk() expects parameter 1 to be array, null given in /data/phpspider/zhask/libs/function.php on line 181
Javascript 获取具有特定属性axios的数组对象_Javascript_Vue.js_Axios - Fatal编程技术网

Javascript 获取具有特定属性axios的数组对象

Javascript 获取具有特定属性axios的数组对象,javascript,vue.js,axios,Javascript,Vue.js,Axios,我通过axios从API调用中获取JSON,目前使用vue显示JSON 以下是控制台中的JSON对象: 0: category_id: "categ1" item_name: "item1" price: 100 stock: 155 1: category_id: "categ2" item_name: "item2" price: 100 stock: 155 2: categ

我通过axios从API调用中获取JSON,目前使用vue显示JSON

以下是控制台中的JSON对象:

0:
  category_id: "categ1"
  item_name: "item1"
  price: 100
  stock: 155
1:
  category_id: "categ2"
  item_name: "item2"
  price: 100
  stock: 155
2:
  category_id: "categ1"
  item_name: "item3"
  price: 100
  stock: 155
3:
  category_id: "categ3"
  item_name: "item4"
  price: 100
  stock: 155
以下是我安装的vue功能(我使用的是axios):

我想做的是只获取类别值为“categ1”的数据,而不是整个json对象。如何实现这一点?

如果响应是一个对象数组,则可以使用

const result=response.filter(item=>item.category_id==='categ1');
在结果数组中,您将拥有categ1作为categoryId的对象,您可以在响应是对象数组的情况下使用

const result=response.filter(item=>item.category_id==='categ1');

在结果数组中,您将有categ1作为categoryId的对象

jquery?为了什么?jquery?为了什么?你不需要解析它axios为你这么做为了捕获,更新答案以使用
filter
而不是
find
并删除
JSON。解析
你不需要解析它axios为你这么做为了捕获,更新了使用
filter
而不是
find
的答案,并删除了
JSON.parse
mounted () {    
  axios.get('link_for_api_endpoint', {  
    headers : { 
      Authorization: 'Bearer ' + access_token,
    },
    params: {
      limit: 250
    }
  })
    .then((response) => {
      this.data = response.data.items;
      //console.log(response);  
      $("#ldr").hide(); 
      removeLoader();   
    })  
    .catch(function (error) {
      console.log(error);   
    })  
    .then(function () { 

    }); 
}