代码之家  ›  专栏  ›  技术社区  ›  Steven

将道具传递给其他组件

  •  0
  • Steven  · 技术社区  · 7 年前

    我正在用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 回复  |  直到 7 年前
        1
  •  2
  •   Manoj    7 年前

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

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

    在 页码B

    <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 .