Reinit Vue3 composable function on route change, using nuxt-composition-api

907 Views Asked by At

I have a route with dynamic id, for example post/:postId and composable function which contains a lot of methods and functions.

when I go from route post/1 to post/2 composable doesn't updated and I got info for the id 1

How to force reinit of the composable function?

<script>
import postFunctions from '~/composable/postHelpers';
import { useContext } from '@nuxtjs/composition-api';

setup() {
   const { store, params } = useContext();
   const { postComments, updatePostText } = postFunctions(params.value.postId)
}

1

There are 1 best solutions below

0
Alina Che On

I used a key in the nuxt-child property and components rerenders full now

  <nuxt-child :key="$route.fullPath" />