如何打开列表,其中parent_id 1

时间:2019-01-04 09:09:58

标签: laravel vue.js

尝试单击打开和折叠手风琴。我能够,但是当我选择另一只手风琴时,它已经接近了。

它应该操作或关闭相同的手风琴。

这是我尝试过的。

我有一个带有下表的类别表。

Categories

我想单击parent_id => 0来打开parent_id => 1的折叠子类别。

Advert.vue

<template>
    <div>
        <h3>List of free ads</h3>
        <ul class="list-group">
            <li v-for="category in categories" :id="'select'+category.id " @click="sendAdvert(category.id)" class="list-group-item">{{ category.name }}</li>
        </ul>
    </div>
</template>

<script>
    export default {
        props: ['categories'],
        data() {
            return {
                adverts: []
            }
        },

        methods: {
            sendAdvert: function (id) {
                const self = this;

                axios.post('adverts/store', {
                    id: id
                }).then((response) => {
                    this.adverts = response.data;
                }).catch((response) => {
                    self.error = 1;
                    console.log('Errors');
                });
            }
        }
    }
</script>

web.php

Route::resource('adverts', 'AdvertController');

AdvertController.php

public function index()
{
    $categories = Category::orderBy('id', 'desc')->get();
    return view('Home.adverts', ['categories' => $categories]);
    //$categories = Category::where('parent_id', 0)->get();
    //return view('Home.adverts', compact('categories'));
}

public function store(Request $request)
{
    $id = $request->id;
    $category = Category::find($id);
    return $category;
}

0 个答案:

没有答案