将道具传递到其他组件

时间:2018-10-30 16:43:38

标签: vue.js nativescript

我正在用VueJs做Nativescript

我有一个模板,我想将一些数据传递到下一个组件/页面。

关于如何捕获the docs的下一个组件中的数据,并没有真正的解释。

唯一接近它的是Passing props to the modal

所以我尝试了。

onSubmit: function (args) {
        console.log(this.searchValue);
        this.$navigateTo(choose_startpoint, {
            props: {
                hospital: this.searchValue
            }
        })
    }

this.searchValue是用户在搜索栏中输入的值

因此在另一个文件中,我尝试像这样捕获它:

props: ['hospital'],

template: `
<Page class="manual_input_page" actionBarHidden="true">
    <StackLayout>
        <Button class="fas btn btn-lb" text="\uf060 Kies je startpunt" @tap="$navigateBack"></Button>
        <SearchBar class="searchbar" :text="searchValue" hint="Search" textFieldBackgroundColor="white" @textChange="onTextChanged" @submit="onSubmit" />         
        <ListView class="list-group" for="items in startpoints" @itemTap="onItemTap" separatorColor="transparent">
          <v-template>
            <Label class="item" :text="items.name" /> 
          </v-template>
        </ListView>
        <Label class="bottom-info" :text="hospital"></Label>
    </StackLayout>        
</Page>
`,

但是它是空的吗?我该怎么办?

1 个答案:

答案 0 :(得分:1)

这应该是Vue检索道具的标准方式,

this.$navigateTo(PageB, {
            props: {
                hello: "World!"
            }
});

PageB

<template>
<Page class="page">
    <ActionBar title="PageB" class="action-bar" />
    <ScrollView>
        <StackLayout class="home-panel">
            <Label class="h2 description-label" :text="$props.hello" />
        </StackLayout>
    </ScrollView>
</Page>
</template>

<script>
   export default {
     props: ['hello'],
     data() {
       return {};
     }
  };
</script>

这里是Playground sample

相关问题