[英]Nuxt - Handle routes at runtime with ssr activated
Hello there: quick question I've你好:我有一个快速的问题
target: 'server'
in the nuxt.config.js具有target: 'server'
/person/maxime
will give me template: PersonsSingle
)一个带有端点的 API 给我,对于给定的路径,关联的模板(例如: /person/maxime
maxime 会给我模板: PersonsSingle
)_pages/person.vue
)处理此页面的 vue 组件(例如: _pages/person.vue
)How can I handle this at runtime?我该如何在运行时处理这个? I guess it's something to do with the middlewares but which one and what is the best strategy here?我想这与中间件有关,但这里的最佳策略是哪一个?
PS: I use this system because two urls with the same structure (eg: /person/maxime
and /person/sam
could lead to two completely different templates ). PS:我使用这个系统是因为两个具有相同结构的 url(例如: /person/maxime
和/person/sam
可能会导致两个完全不同的模板)。 Don't ask why I have to deal with it:/不要问我为什么要处理它:/
This is how I would do it.我就是这样做的。
async asyncData({ $axios }) {
const data = await $axios.$get('...')
const templateType = data.templateType
return {
templateType
}
}
<template>
<div>
<page-1 v-if="templateType === 'foo'" />
<page-2 v-else />
</div>
</template>
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.