[Vuejs]-Add props to component in setup() method / ionic & vue

3👍

You can pass options to the component using the rootParams property in the template:

<template>
  <ion-nav :root="OrderUpdate" :rootParams="rootParams" />
</template>

<script>
import OrderUpdate from '@/components/OrderUpdate.vue'

export default {
  setup() {
    return {
      OrderUpdate,
      rootParams: {
        positions: 'my positions',
        materials: 'my materials',
        order: 'my order',
      }
    }
  }
}
</script>

Alternatively, you can do this programmatically:

<template>
  <ion-nav ref="ionNav" />
</template>

<script>
import { ref, onMounted } from 'vue'
import OrderUpdate from '@/components/OrderUpdate.vue'

export default {
  setup() {
    const ionNav = ref(null)

    const pushOrderUpdate = () => {
      ionNav.value.push(OrderUpdate, {
        positions: 'my positions',
        materials: 'my materials',
        order: 'my order',
      })
    }

    onMounted(() => pushOrderUpdate())

    return {
      ionNav,
    }
  }
}
</script>
👤tony19

Leave a comment