0

I'm trying to show categories of a recipe with <el-tag>, however they're all showing like one under the other: enter image description here

I would like them to be more like this

enter image description here

These tags are inside an <el-table> which has this stucture

<el-table>
    <el-table-column
        prop="name"
        label="Name">
    </el-table-column>
    <el-table-column
        label="Category">
        <template slot-scope="scope">
            <div class="tag-container" v-for="cat in scope.row.categories">
                <el-tag type="success">{{cat.name}}</el-tag>
            </div>
        </template>
    </el-table-column>
    <el-table-column
        align="right">
        <template slot="header" slot-scope="scope">
            <el-input
                v-model="search"
                size="medium"
                placeholder="Search"/>
        </template>

        <template slot-scope="scope">
            <div class="btn-link-edit action-button" @click="edit(scope.row)">
                <i class="fas fa-pencil-alt"></i>
            </div>
            <div class="btn-link-delete action-button" @click="remove(scope.row)">
                <i class="fas fa-trash"></i>
            </div>
        </template>
    </el-table-column>
</el-table>

I also creating the class

.tag-container {
    display: flex;
    flex-direction: row;
}

Is there a way to make them look like the example I showed?

5
  • use flex box Commented Nov 7, 2019 at 22:17
  • @MikeRoss these are inside a table row, can this still be used in there? Commented Nov 7, 2019 at 22:18
  • add some more code or fiddle so we can help more. Commented Nov 7, 2019 at 22:18
  • @MikeRoss I've added the table structure Commented Nov 7, 2019 at 22:24
  • I'm using the Element-ui table component element.eleme.io/#/en-US/component/table Commented Nov 7, 2019 at 22:27

2 Answers 2

3

Use following css class

.container {
  display: flex; /* or inline-flex */
  flex-direction: row
}

Turns out you don't need flex

checkout this codepen

<el-table-column
    label="Category">
    <template slot-scope="scope">
        <template v-for="cat in scope.row.categories">
            <el-tag type="success">{{cat.name}}</el-tag>
        </div>
    </template>
</el-table-column>
Sign up to request clarification or add additional context in comments.

1 Comment

I ended up wrapping the div with another div and setting this class to that and adding a margin-right to the tag class, and this gave me result I wanted, Thanks for your suggestion!
0

I know I'm pretty late to answer this but I just had this issue myself and discovered that the issue was that you're using v-for on the container element. That is why your code was creating multiple containers with the child inside but really you only wanted to create multiple children within that one single container. Also, it would be a good idea to always add the key attribute on the same line you're using v-for for Vue.js

Your code

<div class="tag-container" v-for="cat in scope.row.categories">
    <el-tag type="success">{{cat.name}}</el-tag>
</div>

Code that would fix your issue

<div class="tag-container">
    <el-tag type="success" v-for="cat in scope.row.categories">{{cat.name}}</el-tag>
</div>

Comments

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.