问题描述
我有一个带有动态 id 的路由,例如 post/:postId 和包含很多方法和函数的可组合函数。
当我从路由 post/1 转到 post/2 时,可组合没有更新,我获得了 id 1 的信息
如何强制重新初始化可组合函数?
<script>
import postFunctions from '~/composable/postHelpers';
import { useContext } from '@nuxtjs/composition-api';
setup() {
const { store,params } = useContext();
const { postComments,updatePostText } = postFunctions(params.value.postId)
}
解决方法
我在 nuxt-child 属性中使用了一个键,组件现在重新渲染完整
<nuxt-child :key="$route.fullPath" />