【问题标题】:this.$router.push is not pushing props as expectedthis.$router.push 没有按预期推送道具
【发布时间】:2023-01-18 03:07:50
【问题描述】:

我正在尝试从一个页面导航到另一个页面并将道具传递给新页面组件。这是我的 router.push:

      this.$router.push({ 
          name: 'settings', 
          params: { 
            theme: 'dark' 
          },
          props: true
        }) 
      }   

另一个组件看起来像这样:

export default {
  name: 'settings',
    props: ['theme'],
    mounted () {
      console.log("on mount: " + this.$props.theme)
      console.log(this.$route.params.theme)
  }
    }}
</script>

为什么 theme 总是未定义?我怎样才能得到它的价值?

它正确导航到页面,但我无法访问任何道具。

【问题讨论】:

    标签: vue.js vue-component vuejs3


    【解决方案1】:

    你通过data传递data所以你得到它是这样的:

    export default {
    name: 'settings',
    mounted () {
      console.log(this.$route.params)
    }
    }}
    

    【讨论】:

      猜你喜欢
      • 2022-12-31
      • 1970-01-01
      • 2017-04-04
      • 2019-07-18
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 2015-05-04
      相关资源
      最近更新 更多