【发布时间】:2019-07-02 06:45:52
【问题描述】:
我在我的组件中放置了一个带有 2 个选项卡的 Tabview。首先,我从 API 加载一些数据并用数据呈现 ListView。在另一个选项卡中,我显示了一些其他数据。
第一次显示组件时,API 中的数据没有显示,我有 tab 按 tab 2,然后按 tab 1,然后显示数据。
<template>
<Page class="page">
<TabView :selectedIndex="selectedIndex"
@selectedIndexChange="indexChange">
<TabViewItem title="Tab 1">
<StackLayout orientation="vertical">
<ListView height="90%" class="list-group"
for="item in allCategories">
<v-template>
<StackLayout class="list-group-item"
orientation="horizontal">
<Image :src="item.imageURL"
stretch="aspectFill" class="categoryImage"
width="75" height="75">
</Image>
<Label class="categoryText"
:text="item.element.groupText"/>
</StackLayout>
</v-template>
</ListView>
</StackLayout>
</TabViewItem>
<TabViewItem title="Tab 2">
<Label text="Content for Tab 2" />
</TabViewItem>
</TabView>
</Page>
</template>
created: function () {"url").then(result => {
result.data.forEach(element => {
var imageURL = element.image.imageURL;
this.allCategories.push({element, imageURL })
});
}, error => {
console.log(error);
});
},
我希望在组件首次显示时显示数据,因为选项卡 1 被标记为显示选项卡。有什么想法吗?
这里是操场上的一个例子:https://play.nativescript.org/?template=play-vue&id=9Fk7AS&v=10
【问题讨论】:
-
可以显示获取数据的JS代码吗?或者只是创建一个 Playground 示例? play.nativescript.org/?template=play-vue
-
我在创建的钩子中获取数据:-)
-
结果从何而来?你在那里使用异步吗?你能做一个操场作为例子吗?因为我看不出它为什么不起作用的任何问题。
-
我添加了一个游乐场,您可以在其中看到代码示例出现同样的错误:-)
-
当您提交 Playground 时,请确保添加必要的工作代码来证明您的问题 - 您错过了
ObservableArray的导入。否则,列表似乎按预期工作。
标签: vue.js nativescript nativescript-vue