Skip to content

Instantly share code, notes, and snippets.

Show Gist options
  • Save 1c7/7267d5789eb9883c7883fc0dfe7b78fd to your computer and use it in GitHub Desktop.
Save 1c7/7267d5789eb9883c7883fc0dfe7b78fd to your computer and use it in GitHub Desktop.
Vue, v-for, display special element in certain position
// This is written in Pug syntax. not HTML. but same thing. Pug would compile to HTML
template(v-for='(l, index) in list')
topic-card(:topic='t', :key='t.id')
template(v-if='index == 2')
// [IMPORTANT: display your specifial element here]
@1c7
Copy link
Author

1c7 commented Sep 4, 2018

What is this

Code snippet show you how to display a list with a element in certain position.
For example: you have a card layout.
one row have 4 card.
now you want display an Ad in first row, number 4 position(left to right). you can use this.

Why

it's a simple task. I overcomplicate it with Flex layout, trying to use order property.
and later I come up with this.

it only take me 2 minute to share it on Github gist. so I post it here.
hope it helpful for you

@1c7
Copy link
Author

1c7 commented Sep 4, 2018

The point here is

use v-for + template syntax in Vue.js

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment