【问题标题】:How to foreach array in laravel + vue?如何在 laravel + vue 中 foreach 数组?
【发布时间】:2021-09-19 15:55:30
【问题描述】:

我需要从会话中获取数组。我的控制器代码

return [
        'buys' => request()->session()->get('userBuys')
      ];

Vue 组件

export default {
    data() {
      return {
        buys: {}
      }
    },
    methods: {
        async getBuys() {
            this.$axios.post('/products/mybuys')
                .then(res => {

                    this.buys = res.data.buys
                    
                    this.$root.hideLoading()
                })
        }
    },
    mounted() {
        this.$root.showLoading()
        this.getBuys()
    }
}

所以我得到数组 我需要如何正确地foreach这个数组?我尝试了很多...

【问题讨论】:

标签: laravel vue.js


【解决方案1】:

你的数组中有一个 json,所以你的

购买 = [113, 114,...]

所以你的循环只有数字而不是属性/属性

不带括号试试:

return 'buys' => request()->session()->get('userBuys')

【讨论】:

猜你喜欢
  • 2020-12-11
  • 1970-01-01
  • 2020-11-12
  • 2019-05-15
  • 2016-08-24
  • 1970-01-01
  • 2021-05-13
  • 1970-01-01
  • 2021-01-09
相关资源
最近更新 更多