3

I have a component on my parent page like so:

Detail.vue

Template:

<feature-list :description="description"></feature-list>

Script:

axios.get(`my/end/point`)
.then(res => {
  this.description = res.data.product.description
 })
 .catch(function (error) {
   console.log('error', error)
 })

Features.vue

Template:

<component :is="subcomponent" :height="overallHeight" :width="overallWidth" :length="overallLength"></component>

Script:

components: {
  subcomponent: {
    props: ['overallHeight', 'overallWidth', 'overallLength'],
    /* template: this.description */
  }
}

Expected return value from this.description:

  <el-row :gutter="30">
      <el-col :sm="24">
        <ul class="dimensions d-flex">
          <li class="dimension">
            <img src="/length.jpg" alt="">
            <h4 class="title">Length</h4>
            <p class="base-copy">{{length}}</p>
          </li>
          <li class="dimension">
            <img src="/height.jpg" alt="">
            <h4 class="title">Height</h4>
            <p class="base-copy">{{height}}</p>
          </li>
          <li class="dimension">
            <img src="/width.jpg" alt="">
            <h4 class="title">Width</h4>
            <p class="base-copy">{{width}}</p>
          </li>
        </ul>
      </el-col>
    </el-row>

How can I send the template to the component? and render the values (lenth, width and height)

Something like this, only difference being, the template comes from an ajax call.

1 Answer 1

1

After some digging, I've found a way to solve this, the idea is to pass the template and the props as an object to the is prop.

The code will look like this,

<component 
 :is="description && { template: `<div>${description}</div>`, props: ['height', 'width', 'length'] }" 
 :height="overallheight" 
 :width="overallwidth" 
 :length="overalllength">
</component>
Sign up to request clarification or add additional context in comments.

Comments

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.