0

我一直在尝试使用 Vuejs3 useHead 包并添加动态标题和描述元,但我得到 $route 未定义....我需要帮助...

<router-link :to="{name:'productDetails', params:{id:rope._id, title:rope.title, price: rope.price, description:rope.description, quantity:rope.totalQuantity}}">

peoductDetails.vue:

 setup(){

    useHead({
      title: this.$route.params.title,
      meta: [
        {
          name: `description`,
          content: `blalala`
        },
      ],
    })
  },

4

1 回答 1

0

您需要使用useRoute()才能访问路由器,因为在设置挂钩this中不引用组件实例

setup(){
    const route = useRoute();
    useHead({
        title: route.params.title,
        meta: [
            {
                name: `description`,
                content: `blalala`
            },
        ],
    })
},
于 2021-11-19T21:22:46.303 回答