Quasar Framework SSR 无法正常工作及preFetch方法未执行问题求助
Quasar Framework SSR 无法正常工作及preFetch方法未执行问题求助
我最近尝试让Quasar-Skeleton-App通过SSR运行,已经用TypeScript和Vite搭建好了Quasar骨架项目,也在Quasar里启用了SSR,还在组件里实现了preFetch方法,但这个方法完全没执行,页面还是客户端渲染的,根本没法预获取数据。感觉是漏掉了某些文档里没讲清楚的配置,实在搞不懂哪里错了,来求助大家!
我的quasar.config.js相关配置如下:
preFetch: true, ssr: { pwa: false, prodPort: 3000, // The default port that the production server should use middlewares: [ 'render', // keep this as last one ], },
我的ExampleComponent.vue里写了一个preFetch函数,只是简单打印日志,但从来没输出过:
<script lang="ts"> import { defineComponent, PropType, computed, ref, toRef, Ref } from 'vue'; import { Todo, Meta } from './models'; function useClickCount() { const clickCount = ref(0); function increment() { clickCount.value += 1; return clickCount.value; } return { clickCount, increment }; } function useDisplayTodo(todos: Ref<Todo[]>) { const todoCount = computed(() => todos.value.length); return { todoCount }; } export default defineComponent({ name: 'ExampleComponent', props: { title: { type: String, required: true, }, todos: { type: Array as PropType<Todo[]>, default: () => [], }, meta: { type: Object as PropType<Meta>, required: true, }, active: { type: Boolean, }, }, preFetch({ store, currentRoute, previousRoute, redirect, ssrContext, urlPath, publicPath, }) { // eslint-disable-next-line no-console console.log('preFetch', { store, currentRoute, previousRoute, redirect, ssrContext, urlPath, publicPath, }); }, setup(props) { return { ...useClickCount(), ...useDisplayTodo(toRef(props, 'todos')) }; }, }); </script>
到底漏掉了什么配置?怎么才能让Quasar的SSR正常工作,并且让preFetch方法执行起来?
备注:内容来源于stack exchange,提问作者delete
相关产品推荐
相关产品推荐

