nativescript passing props vue

 ̄綄美尐妖づ 提交于 2021-02-19 01:42:39

问题


Having trouble passing a prop in nativescript this.$navigateTo()

 <template>
       <stack-layout v-for="meme in memes">
        <Image :src="meme.url" @tap="goToEditPage(meme.url)"/>
       </stack-layout>
      </template>

<script>
import EditMeme from './EditMeme'
  export default {
    computed: {
      memes(){
        return this.$store.getters.memes
      }
    },
    components: {
      EditMeme
    },
    methods: {
      goToEditPage(ImageUrl) {
        this.$navigateTo(EditMeme, { context: { propsData: { Image: ImageUrl } }});
      }
    }
  }

</script>

I tried passing props this way

still, In the child component I get an undefined , this is the child component :

  export default {
props: ['Image'],
methods: {
  onButtonTap() {

    console.log(this.props);
  }
  }}

Any ideas? I'm new with vue.js so there is a good chance I'm missing something basic in my code


回答1:


The correct way to navigate is this:

this.$navigateTo(confirmRoute, {
                    props: {
                        hospital: "hospital A",
                        startpoint: "startpoint Y",
                        endpoint: "point x"
                    }
                })

You just need to catch it like this then or you next page:

 props: ['hospital', 'startpoint', 'endpoint'],

and you can use it then like this in the JS:

this.hospital
this.startpoint
this.endpoint

If you wish to use it in the template you need to this:

<template>
    <Page>
            <Label  :text="$props.hospital.name">
            </Label>
        </FlexBoxLayout>
    </Page>
</template>



回答2:


In case using nativescript vue:

@tap="$navigator.navigate('/settings/your_page', {props: { isEditMode: true }})"

In the your_page.vue:

props: { isEditMode: { type: Boolean, default: false, required: false } },

mounted() { console.log("isEditMode :>> ", this.isEditMode); }



来源:https://stackoverflow.com/questions/53190292/nativescript-passing-props-vue

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!