Vue Router是一个用于单页面应用程序的路由库,设计用于Vue.js框架。
因此,我使用 MyServer.com/vue/ 等子目录在我的服务器中部署此应用程序。 在我的App.vue中只显示,在本地这个应用程序运行顺利,并且
嗨,我有一个带有路由器、Pinia、eslint 和 TypeScript 的 Quasar 项目。 我的问题是,如果组件直接注入到布局(下面的 MainLayout)中,则组件会加载,但不会加载......
我正在尝试从 vue 路由器的路由生成路由名称。 目标是使用辅助函数 findRouteByName() 来查找路线。 但辅助函数的参数应该有...
如何使用 Vue 3 根据 Vue 路由添加不同的 html 元
我一直在尝试解决如何没有多大成功(我不认为我知道谷歌的正确内容)如何为我的Vue 3应用程序的不同路由(使用Vue Router)拥有不同的元。 ..
Vue Router - 设置单独的可选 url 参数时可选 url 参数的默认值
我有以下路线: 导出常量 personRoutes: RouteRecordRaw[] = [ { 路径: '/person/:id?/:handedSlug?', 名称:'人', 组件: () => import('./view/person'), }, ]; ...
我希望窗口默认滚动,但不在主页上滚动(当我更改语言变量时)。我像这样改变了 Vue 路由器中的回调 滚动行为(到,从,保存位置){ 如果(
$router.push 在 vuejs 应用程序中不起作用
我有以下vue代码:login.vue来自https://github.com/themeselection/sneat-vuetify-vuejs-admin-template-free 从 '@/views/pa... 导入 AuthProvider </desc> <question vote="0"> <p>我有以下vue代码:login.vue来自<a href="https://github.com/themeselection/sneat-vuetify-vuejs-admin-template-free" rel="nofollow noreferrer">https://github.com/themeselection/sneat-vuetify-vuejs-admin-template-free</a></p> <pre><code><script setup lang="ts"> import AuthProvider from '@/views/pages/authentication/AuthProvider.vue' import logo from '@images/logo.svg?raw' const form = ref({ email: '', password: '', remember: false, message:'' }); function login(){ // Make a POST request to the CodeIgniter API endpoint using fetch fetch('http://localhost:8080/api/validateCredentials', { method: 'POST', headers: { 'Content-Type': 'application/json' }, body: JSON.stringify({ username: form.value.email, password: form.value.password }) }) .then(response => response.json()) .then(data => { if (data.status === 'success') { form.value.message = 'Login successful!'; $router.push('dashboard'); } else { form.value.message = data.message; } }) .catch(error => { form.value.message = 'An error occurred. Please try again later.'; }); } const isPasswordVisible = ref(false) </script> <template> <div class="auth-wrapper d-flex align-center justify-center pa-4"> <VCard class="auth-card pa-4 pt-7" max-width="448" > <VCardItem class="justify-center"> <template #prepend> <div class="d-flex"> <div class="d-flex text-primary" v-html="logo" /> </div> </template> <VCardTitle class="text-2xl font-weight-bold"> sneat </VCardTitle> </VCardItem> <VCardText class="pt-2"> <h5 class="text-h5 mb-1"> Welcome to sneat! 👋🏻 </h5> <p class="mb-0"> Please sign-in to your account and start the adventure </p> </VCardText> <VCardText> <!--<VForm @submit.prevent="$router.push('/')">--> <VForm @submit.prevent="login"> <VRow> <div v-if="form.message" class="danger"> {{form.message}} </div> <!-- email --> <VCol cols="12"> <VTextField v-model="form.email" autofocus placeholder="[email protected]" label="Email" type="email" /> </VCol> <!-- password --> <VCol cols="12"> <VTextField v-model="form.password" label="Password" placeholder="············" :type="isPasswordVisible ? 'text' : 'password'" :append-inner-icon="isPasswordVisible ? 'bx-hide' : 'bx-show'" @click:append-inner="isPasswordVisible = !isPasswordVisible" /> <!-- remember me checkbox --> <div class="d-flex align-center justify-space-between flex-wrap mt-1 mb-4"> <VCheckbox v-model="form.remember" label="Remember me" /> <RouterLink class="text-primary ms-2 mb-1" to="javascript:void(0)" > Forgot Password? </RouterLink> </div> <!-- login button --> <VBtn block type="submit" > Login </VBtn> </VCol> <!-- create account --> <VCol cols="12" class="text-center text-base" > <span>New on our platform?</span> <RouterLink class="text-primary ms-2" to="/register" > Create an account </RouterLink> </VCol> <VCol cols="12" class="d-flex align-center" > <VDivider /> <span class="mx-4">or</span> <VDivider /> </VCol> <!-- auth providers --> <VCol cols="12" class="text-center" > <AuthProvider /> </VCol> </VRow> </VForm> </VCardText> </VCard> </div> </template> <style lang="scss"> @use "@core/scss/template/pages/page-auth.scss"; .danger{color:red;padding:20px;} </style> </code></pre> <p>当我在登录成功中使用 $router.push 时,控件切换到 Promise 对象的 catch 块,并且我收到错误。如果我避免使用推送语句,我就会登录成功。当登录成功时,我想重定向到仪表板页面。</p> <p>我的路由器/index.ts</p> <pre><code>import { createRouter, createWebHistory } from 'vue-router' const router = createRouter({ history: createWebHistory(import.meta.env.BASE_URL), routes: [ { path: '/', redirect: '/login' }, { path: '/', component: () => import('../layouts/default.vue'), children: [ { path: 'dashboard', component: () => import('../pages/dashboard.vue'), }, { path: 'account-settings', component: () => import('../pages/account-settings.vue'), }, { path: 'typography', component: () => import('../pages/typography.vue'), }, { path: 'icons', component: () => import('../pages/icons.vue'), }, { path: 'cards', component: () => import('../pages/cards.vue'), }, { path: 'tables', component: () => import('../pages/tables.vue'), }, { path: 'form-layouts', component: () => import('../pages/form-layouts.vue'), }, ], }, { path: '/', component: () => import('../layouts/blank.vue'), children: [ { path: 'login', component: () => import('../pages/login.vue'), }, { path: 'register', component: () => import('../pages/register.vue'), }, { path: '/:pathMatch(.*)*', component: () => import('../pages/[...all].vue'), }, ], }, ], }) export default router </code></pre> <p>请帮忙找出错误在哪里。</p> </question> </body></html>
useHead 正在更新已安装的标题,但未在激活的挂钩上更新
我使用 useHead 来更新页面中的标题,标题在安装页面时更新,但是当我重新访问页面时,页面标题不会更新。 当我重新访问页面标题时应该是
我有一个 Vue 组件,它有一个名为“title”的 prop,例如: 导出默认值{ 道具:['标题'], 数据() { 返回 { } } } 我导航到该组件
使用: - [email protected] [email protected] [email protected] 文件夹结构: 页面 |_index.vue |_ 项目 |_ [id].vue 索引.vue: 使用: - [email protected] - [email protected] - [email protected] 文件夹结构: pages |_ index.vue |_ items |_ [id].vue index.vue: <template> <div> <ul> <li v-for="item in items" :key="item"> <NuxtLink :to="`${item}`"> {{ item }} </NuxtLink> </li> </ul> </div> </template> <script setup lang="ts"> const items = [ 'items/1', 'items/2', 'items/3', ]; </script> [id].vue: <template> <div> <ItemDetails v-bind="data.details" /> <ItemDetailsTabs v-bind="data" /> </div> </template> <script setup lang="ts"> import { useFetch } from '#app'; import { useRoute } from 'vue-router'; import ItemDetails from '...'; import ItemDetailsTabs from '...'; import { ItemDetailsProps } from '...'; import { ItemDetailsTabsProps } from '...'; const { id } = useRoute().params; const endpoint = `/api/items?id=${id}`; interface ItemData extends ItemDetailsTabsProps { details: ItemDetailsProps; } const { data } = await useFetch(endpoint) as unknown as { data: ItemData; }; </script> 如果在 index.vue 中我通过 v-for 列出了所有项目, NuxtLink 有 target="_blank - 打开项目页面成功(这里没有问题)。 不幸的是,我不允许使用 target=_blank (应该在同一选项卡中打开页面),但这会导致以下错误: runtime-core.esm-bundler.js:40 [Vue warn]: Unhandled error during execution of scheduler flush. This is likely a Vue internals bug. [Vue Router warn]: uncaught error during route navigation: warn @ vue-router.mjs:35 triggerError @ vue-router.mjs:3449 (anonymous) @ vue-router.mjs:3487 Promise.catch (async) handleScroll @ vue-router.mjs:3487 finalizeNavigation @ vue-router.mjs:3335 (anonymous) @ vue-router.mjs:3207 Promise.then (async) pushWithRedirect @ vue-router.mjs:3174 push @ vue-router.mjs:3099 replace @ vue-router.mjs:3102 updateCountry @ useCountrySelector.ts:38 callWithErrorHandling @ runtime-core.esm-bundler.js:173 callWithAsyncErrorHandling @ runtime-core.esm-bundler.js:182 job @ runtime-core.esm-bundler.js:1812 callWithErrorHandling @ runtime-core.esm-bundler.js:173 flushJobs @ runtime-core.esm-bundler.js:406 Promise.then (async) queueFlush @ runtime-core.esm-bundler.js:298 queueJob @ runtime-core.esm-bundler.js:292 (anonymous) @ runtime-core.esm-bundler.js:5761 triggerEffect @ reactivity.esm-bundler.js:400 triggerEffects @ reactivity.esm-bundler.js:390 triggerRefValue @ reactivity.esm-bundler.js:1021 (anonymous) @ reactivity.esm-bundler.js:1158 triggerEffect @ reactivity.esm-bundler.js:400 triggerEffects @ reactivity.esm-bundler.js:385 triggerRefValue @ reactivity.esm-bundler.js:1021 (anonymous) @ reactivity.esm-bundler.js:1158 triggerEffect @ reactivity.esm-bundler.js:400 triggerEffects @ reactivity.esm-bundler.js:385 triggerRefValue @ reactivity.esm-bundler.js:1021 set value @ reactivity.esm-bundler.js:1066 finalizeNavigation @ vue-router.mjs:3334 (anonymous) @ vue-router.mjs:3207 Promise.then (async) pushWithRedirect @ vue-router.mjs:3174 push @ vue-router.mjs:3099 navigate @ vue-router.mjs:2189 callWithErrorHandling @ runtime-core.esm-bundler.js:173 callWithAsyncErrorHandling @ runtime-core.esm-bundler.js:182 invoker @ runtime-dom.esm-bundler.js:345 TypeError: Cannot read properties of null (reading 'parentNode') at parentNode (runtime-dom.esm-bundler.js:35:30) at ReactiveEffect.componentUpdateFn [as fn] (runtime-core.esm-bundler.js:5731:17) at ReactiveEffect.run (reactivity.esm-bundler.js:190:25) at instance.update (runtime-core.esm-bundler.js:5763:56) at updateComponent (runtime-core.esm-bundler.js:5588:26) at processComponent (runtime-core.esm-bundler.js:5521:13) at patch (runtime-core.esm-bundler.js:5119:21) at patchSuspense (runtime-core.esm-bundler.js:1253:13) at Object.process (runtime-core.esm-bundler.js:1204:13) at patch (runtime-core.esm-bundler.js:5125:26) Uncaught (in promise) TypeError: Cannot read properties of null (reading 'subTree') at move (runtime-core.esm-bundler.js:6043:34) at move (runtime-core.esm-bundler.js:6043:13) at Object.resolve (runtime-core.esm-bundler.js:1409:21) at runtime-core.esm-bundler.js:1523:30 如果控制台记录,数据似乎已成功获取。打开页面并收到此错误后,在页面刷新时,将显示 ItemDetails 页面,并按预期显示获取的数据。 我缺少什么?任何帮助将不胜感激!
Vue Router this.$router.push 不适用于方法
我正在登录,但是登录方法成功后,我正在为 $router 对象推送一条路由,但它不起作用,有人可以帮助我吗? 我的代码: 登录(){ this.attemptLogin({...thi...
如何修复[Vue Router warn]:导航时丢弃无效参数“id”
我使用 VueJS 3.3 和 Vue Router v4。 具有以下路由结构。 Vue 不断抱怨: [Vue Router warn]:导航时丢弃无效参数“id”。 我读过如果我推动
如何在没有按钮的情况下在 vue 中使用 router.back()
所以我当前的项目使用 vue 及其包,我想导航到最后一页而不使用编码到应用程序中的物理按钮,我想使用浏览器的按钮导航...
Vue.js 组件即使使用 mode="out-in" 也不会转换出来
我对 vue.js 比较陌生,一直在尝试让我的路由页面在用户切换到新页面时淡入和淡出。我以为用vue会相当简单,但是我已经泪流满面了……
我在数据库中保存了一个与此类似的字符串: Lorem #ipsum dolor sit amet,#consectetur adipiscing elit,sed do #eiusmod tempor incididunt ut labore et dolore magna aliqua。 正如你所看到的...
考虑以下代码: const 路由器 = useRouter() 等待 router.push({ name: 'NonExistingRoute', // 没有打字稿错误 ): }) 给出了一个不存在的路由名称,但没有 TypeScript 错误
我正在使用: [email protected] [email protected] vue-路由器@4.1.6 我正在使用 Firebase,我使用 pinia Store 进行身份验证。我现在这样做的方式是: 我有一家叫 sto 的 pinia 店...
Vue3 Transition 不适用于 Route 内的 Router-Link
前几天我试图设置一个 vue-router 页面。基本思想是在每条路线上都有一个按钮可以转到另一条路线。我试着用简单的淡入淡出过渡来制作动画,而
单页应用程序:进入/重新加载应用程序时如何在 Vue.js 3 Composition API 中卸载应用程序?
Webpack 服务器在浏览器控制台中显示以下警告: [Vue warn]: 宿主容器上已经挂载了一个应用实例。 如果你想在同一个主机上安装另一个应用程序
我正在使用 Suspense,并在页面上获取异步数据。在初始化回退加载指示器是可见的,但在切换页面时我会保留当前页面内容,直到新页面准备好 + nprogress b ...