1

I am trying to create a child component where the parent passes a prop and then the child computes several id's based on the passed prop. So far the only way I have managed to do it is by doing a computed property for each of the ids. I am sure there has to be an easier way to do it directly in the template.

For example the parent:

 <Dates id="secondary_school" />

the Dates component:

<template>
  <div :id="{{id}}_container">
    <div :id="{{id}}_timeline">
     <input :id="{{id}}_school_name" />
     ...
    </div>
  </div>
</template>

I know I cannot use squiggly brackets because Vue will complain about interpolation but if I do not use them then it doesn't find the prop being passed.

Would it be possible to have something similar to:

    <template>
      <div :id="id" + "_container">
        <div :id="id" + "_timeline">
         <input :id="id" + "_school_name" />
         ...
        </div>
      </div>
    </template>

1 Answer 1

3

You can achieve that using something like this:

<div :id="id+'_container'">

<!-- Possible output: <div id="secondary_school_container"> -->

Instead of writing it like this:

<div :id="{{id}}_container">
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.