Programing

vue 라우터의 메타 제목으로 매개 변수 전달

c10106 2022. 3. 7. 21:26
반응형

vue 라우터의 메타 제목으로 매개 변수 전달

나는 메타 타이틀에 경로 파라미터를 전달하고 싶은데 어떻게 해야 할지 모르겠어.내가 시도했던 것이 제목 탭에서 정의되지 않은 상태로 계속 돌아온다.

{
  path:'/profile/:name',
  component: Profile,
  meta: { title: route.param.name + 'place' }
}

컴포넌트에서는 이것을 더 쉽게 할 수 있다.그 부품에 이런 걸 써보겠다.

created: function () {
  document.title = this.$route.params.name + ' place'
}

제목 메타 함수를 제거하십시오.

{
  path:'/profile/:name',
  component: Profile,
}

넘겨도 좋다.props대신:

{
  path:'/profile/:name',
  component: Profile,
  props: route => ({ title: route.param.name + 'place' })
}

그리고 나서 정의하십시오.title을 지지하다Profile구성 요소:

props: {
  title: {
    type: String,
    default: '',
  },
},

meta를 함수로 사용할 수 있다.

{
  path:'/profile/:name',
  component: Profile,
  meta: (route) => { title: route.params.name + 'place' }
}

그런 다음 템플릿의 함수로 호출하십시오.

this.$route.meta(this.$route)

참조URL: https://stackoverflow.com/questions/52207904/passing-param-to-meta-title-in-vue-router

반응형