在 nativescript-vue 视图模态组件中显示数组数据

Showing array data in nativescript-vue view modal component

我想从父级创建模态组件并在列表视图中的模态中填充数据

如果组件已经创建,我没有问题,但我想要在该父页面中创建组件

template>
    <Page class="page">
        <ActionBar title="Modal Data" class="action-bar"></ActionBar>
        <ScrollView>
            <StackLayout class="m-20">
                <Button text="Button" @tap="goToDetailPage" />
            </StackLayout>
        </ScrollView>
    </Page>
</template>

<script>
    const Detail = {
        template: `
    <Page>
        <ActionBar title="Asal Ikan" />
        <StackLayout>

            <ListView class="list-group" for="mylist in mylists" style="height:600px;">
                <v-template>
                <FlexboxLayout flexDirection="row" class="list-group-item">

                    <Label :text="mylist.name" style="width:100%;" @tap="closeModal" />

                </FlexboxLayout>
            </v-template>
            </ListView>



        </StackLayout>
     </Page>
        `
    };
    export default {
        data() {
            return {
                mylists: [{
                        code: "SL",
                        name: "Sinjai"
                    },
                    {
                        code: "MK",
                        name: "Makasar"
                    }
                ]
            };
        },
        methods: {

            goToDetailPage() {
                this.$showModal(Detail);
            }
        }
    };
</script>

我的列表中的数据未显示。 这里是操场 link : https://play.nativescript.org/?template=play-vue&id=WlzgRU&v=104

您可能希望改进/更正您的代码中的许多内容。

  1. Detail 是独立组件,它无法访问 Master (HelloWorld) 组件中的数据。如果您想访问相同的数据,您应该在 props 中传递 mylists
  2. Page 只能托管在 Frame 内,有效的 Page 只能有 ActionBar。由于您尚未在 Detail 组件中定义 Frame,因此它将无效。
  3. 对于 ListView,使用 itemTap 事件而不是向单个组件添加事件侦听器。

Updated Playground