【问题标题】:Reinit Vue3 composable function on route change, using nuxt-composition-api使用 nuxt-composition-api 在路由更改上重新初始化 Vue3 可组合函数
【发布时间】:2021-09-17 08:23:55
【问题描述】:

我有一个动态 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.js vuejs3 vue-mixin


    【解决方案1】:

    我在 nuxt-child 属性中使用了一个键,组件现在完全重新渲染

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

    【讨论】:

      猜你喜欢
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 2021-10-02
      • 2021-11-23
      • 2021-03-16
      • 2012-06-27
      相关资源
      最近更新 更多