无法将对象推送到数组vue-js

时间:2019-07-17 03:43:29

标签: vue.js

我无法将对象推送到数组。

这是代码:

snapshot.forEach(function(childSnapshot) {
        var item = childSnapshot.val();
        item.key = childSnapshot.key;
        var data = {
          name: item.name,
          price: item.price,
          details: item.details
        };
        this.products.push(data);
      });

products是一个空数组。

products:[]

我在控制台日志中看到数据:

{name: "java", price: "zero", details: "nothing"}
{name: "nfdg", price: 145, details: "fkshfksf"}
{name: "nfdg", price: 145, details: "fkshfksf"}
{name: "nfdg", price: 145, details: "fkshfksf"}
{name: "nfdg", price: 145, details: "fkshfksf"}

谢谢

1 个答案:

答案 0 :(得分:0)

)