【问题标题】:vue router react on parent component using a modalvue 路由器使用模态对父组件做出反应
【发布时间】:2019-11-21 21:19:36
【问题描述】:

访问/父页面并渲染父组件,

访问/parent/modal并渲染Child组件(打开一个modal组件),

导航回 /parent(试图在父组件中呈现更新的数据)这是我卡住的地方!

保存数据后,我正在跟踪路由参数,并使用函数获取数据。但是,父级没有反应。

我必须手动刷新或在函数中添加 location.reload() 以查看数据更改。

为什么父级对路由器更改没有反应?

我已经设置了路线表:

'$route' (to, from) {
    this.fetchUpdate
}
  • 没用

然而,在 vue.js 文档中 beforeRouteEnter 和 beforeRouteUpdate (to, from, next) 显然是首选方法,并且数据仍然像手表一样被获取,但父级不是响应式的。

当我没有将路由设置为嵌套(/父/子)时它可以工作,但是“灯箱”效果将不存在并且看起来像一个全尺寸的页面加载。

//Route Structure

{
    path: '/dashboard',
    name: 'dashboard',
    component: Dashboard,
    meta: {
        requiresAuth: true
    },
    children: [
        {
            path: 'modal',
            name: 'modal',
            component: Modal,
            meta: {
              requiresAuth: true
            }
        }
    ]
},

// Parent Structure

beforeRouteEnter (to, from, next) {
    next(vm => {
        vm.fetchUpdate()
        next();
    })
},
beforeRouteUpdate (to, from, next) {
    firebaseDb.collection('post').where('post_id',
      '==', to.params.post_id).get()
        .then(querySnapshot => {
            querySnapshot.forEach(doc => {
                next(vm => {
                  vm.post_id = doc.data().post_id
                  vm.title = doc.data().title
                  vm.paragraph = doc.data().paragraph
                })
            })
        })
}
,

我们只是试图让编辑帖子的模态版本工作,因为它更加用户友好,我们只是完全卡住了

如果您需要更多代码结构,请告诉我

【问题讨论】:

    标签: javascript vue.js vue-router vue-reactivity


    【解决方案1】:

    请显示父组件的完整sn-p。

    【讨论】:

      猜你喜欢
      • 2022-06-28
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 2016-02-24
      • 1970-01-01
      • 2017-05-06
      • 2020-01-10
      • 2019-06-16
      相关资源
      最近更新 更多