0

I have a data attribute like so:

<div data-id="">

In my markdown file I have frontmatter variable like so:

id: rick

Now I want to pass that object into data-id which only lets me add string. How to make like so:

<div data-id="id"> or <div data-id={{ id }}> or <div :data-id={{ id }}>

I use vuejs.

1 Answer 1

1

To bind attributes to an element (or component) you use

<div :data-id="id">
   ...
</div>

window.onload = () => {
  new Vue({
    el: '#app',
    data () {
      return {
        id: 123
      }
    }
  })
}
<script src="https://cdnjs.cloudflare.com/ajax/libs/vue/2.5.0/vue.js"></script>

<div id="app">
  <div :data-id="id">
    This is rendered as div with and data-id="123"
  </div>
</div>

Sign up to request clarification or add additional context in comments.

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.