0

The v-for in the code below seem prevent any output.

The browser just shows <!---->

It should display 5 lines of <div class="Polaris-SkeletonBodyText"></div>

Vue.component('skeleton-body', {
  props: ['lines'],
  template: `<div>
    <div v-for="n in lines" :class="lines">
      <div class="Polaris-SkeletonBodyText"></div>
    </div>
  </div>`
});

Vue.component('skeleton-display', {
  props: ['size'],
  template: `<div :class="['Polaris-SkeletonDisplayText__DisplayText', 'Polaris-SkeletonDisplayText--size--' + size]"></div>`
});

Vue.component('translation', {
  props: ['phrase', 'type', 'lines', 'size'],
  template: `<template v-if="!phrase">
    <component :is="getSkeletonComponent" :lines="lines" :size="size"></component>
  </template>
  <template v-else>
    <span>{{ phrase }}</span>
  </template>`,
  computed: {
    getSkeletonComponent() {
      if (this.type === 'body') {
        console.log (this.lines);
        return 'skeleton-body';
      }
      else if (this.type === 'display') {
        switch (this.size) {
          case 'small':
            this.size = 'Small'
            break;
          case 'medium':
          default:
            this.size = 'Medium'
            break;
          case 'large':
            this.size = 'Large'
            break;
          case 'extraLarge':
            this.size = 'ExtraLarge'
            break;
        }
        return 'skeleton-display';
      }
    }
  }
});

new Vue({
el: '#app',
data: {
language: {}
},
methods: {}
})
<head>
<script src="https://cdnjs.cloudflare.com/ajax/libs/vue/2.3.2/vue.min.js"></script>
<link type="text/css" rel="stylesheet" href="https://unpkg.com/@shopify/polaris@10.30.0/build/esm/styles.css">
</head>
<body>
<div id="app">
  <translation :phrase="language.test" type="body" lines="5"></translation>
</div>
</body>
Asa Carter
  • 2,207
  • 5
  • 32
  • 62
  • Does this answer your question? [Cannot use v-for on stateful component root element because it renders multiple elements?](https://stackoverflow.com/questions/44193822/cannot-use-v-for-on-stateful-component-root-element-because-it-renders-multiple) – Sysix Jun 20 '23 at 21:36
  • No it doesn't seem to. There are mo errors or warnings in the console. I added a parent
    element around the loop and it made no difference.
    – Asa Carter Jun 20 '23 at 21:42
  • @Sysix Actually, the parent div was one of the issues. – Asa Carter Jun 20 '23 at 22:01

1 Answers1

0

<div v-for="n in parseInt(lines)" :key="n">

It seems the value of lines was parsed as a string.

Asa Carter
  • 2,207
  • 5
  • 32
  • 62
  • Yes, you simply set the attribute (`lines="5"`), so it was interpreted as a string. If you _bound_ it (`:lines="5"`), it would be parsed as a JavaScript expression, and hence as the number `5` instead of the string `"5"`. – Darryl Noakes Jun 20 '23 at 22:06