Vue JS 元件中的 v-for 不會輸出任何內容
P粉268654873
P粉268654873 2023-09-11 22:43:19
0
1
493

下面程式碼中的 v-for 似乎阻止了任何輸出。

瀏覽器只顯示

它應該會顯示 5 行

#

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>

P粉268654873
P粉268654873

全部回覆(1)
P粉618358260

#看起來lines的值被解析為字串。

熱門教學
更多>
最新下載
更多>
網站特效
網站源碼
網站素材
前端模板
關於我們 免責聲明 Sitemap
PHP中文網:公益線上PHP培訓,幫助PHP學習者快速成長!