【问题标题】:nativescript vue for loop on labelnativescript vue for 在标签上循环
【发布时间】:2019-06-05 11:27:33
【问题描述】:

我正在使用nativescript vue,我想知道如何执行 for 循环。我现在拥有的代码是:

<template>
    <GridLayout columns="0" rows="*,*,*">
        <Label :text="title" for="title in titles"/>
    </GridLayout>
</template>

<script>
    export default {
        data() {
            return {
                titles: ['foo', 'bar', 'test']
            }
        }
    }
</script>

我收到的错误是:[Vue warn]: Property or method "title" is not defined on the instance but referenced during render. Make sure that this property is reactive, either in the data option, or for class-based components, by initializing the property. See: https://vuejs.org/v2/guide/reactivity.html#Declaring-Reactive-Properties.

【问题讨论】:

    标签: vue.js nativescript nativescript-vue


    【解决方案1】:

    使用v-for

    例如

    <template>
        <Page class="page">
            <ActionBar title="Home" class="action-bar" />
            <ScrollView>
                <StackLayout class="home-panel">
                    <!--Add your page content here-->
                    <Label :text="title" v-for="title in titles" />
                </StackLayout>
            </ScrollView>
        </Page>
    </template>
    
    <script>
        export default {
            data() {
                return {
                    titles: ["foo", "bar", "test"]
                };
            }
        };
    </script>
    
    <style scoped>
        .home-panel {
            vertical-align: center;
            font-size: 20;
            margin: 15;
        }
    
        .description-label {
            margin-bottom: 15;
        }
    </style>
    

    Playground demo here

    【讨论】:

      猜你喜欢
      • 1970-01-01
      • 2022-01-01
      • 1970-01-01
      • 2021-07-12
      • 2019-01-31
      • 2020-11-29
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      相关资源
      最近更新 更多