vue-router的key属性值

设置 router-view 的 key 属性值为 $route.fullPath时,报错Property or method "key" is not defined on the instance but referenced during render. Make sure that this property is reactive, either in the data option, or for class-based components, by initializing the property.

【相关推荐】



  • 看下这篇博客,也许你就懂了,链接:关于Vue中给router-view 设置key的原因($route-fullPath)
  • 除此之外, 这篇博客: vue中 给router-view 组件的 绑定 key 的原因中的 3. 设置 router-view 的 key 属性值为 $route.fullPath 部分也许能够解决你的问题, 你可以仔细阅读以下内容或跳转源博客中阅读:

    从/page/1 => /page/2, 由于这两个路由的$route.fullPath并不一样, 所以组件被强制不复用, 相关钩子加载顺序为:
    beforeRouteUpdate => created => mounted

    从/page?id=1 => /page?id=2, 由于这两个路由的$route.fullPath并不一样, 所以组件被强制不复用, 相关钩子加载顺序为:
    beforeRouteUpdate => created => mounted


如果你已经解决了该问题, 非常希望你能够分享一下解决方案, 写成博客, 将相关链接放在评论区, 以帮助更多的人 ^-^