小编des*_*cne的帖子

Vue-router 2改变路由但不更新视图?

我有一个使用以下网站的登录问题:

  • Vue.js v2.0.3
  • vue-router v2.0.1
  • vuex v0.8.2

在routes.js我有一个简单的拦截器设置

router.beforeEach((to, from, next) => {
if (to.matched.some(record => record.meta.requiresAuth)) {
    // this route requires auth, check if logged in
    // if not, redirect to login page.
    if (!router.app.auth.isUserLoggedIn) {
        next({
            path: '/login',
            query: { redirect: to.fullPath }
        })
    } else {
        next()
    }
} else {
    next() // make sure to always call next()!
}
Run Code Online (Sandbox Code Playgroud)

})

并且login.vue,在使用Google API仅用于登录成功后处理登录页面逻辑我称之为:

this.login(userData).then( 
    () => this.$router.push(this.redirectToAfterLogin), // Login success
    () => {} …
Run Code Online (Sandbox Code Playgroud)

javascript vue.js vue-router vuejs2

12
推荐指数
2
解决办法
7566
查看次数

Vue.js的CORS问题

我正在使用:

  • Vue 2.0.3
  • Vue路由器2.0.1
  • vuex 0.8.2
  • vue资源0.7.0

在尝试使用远程API而不是本地运行的API登录到我的页面后,出现以下错误提示:

vue-resource.common.js?2f13:1074 OPTIONS 

https://mywebsite/api/auth/login 

(anonymous function) @     vue-resource.common.js?2f13:1074
Promise$1            @     vue-resource.common.js?2f13:681
xhrClient            @     vue-resource.common.js?2f13:1033
Client               @     vue-resource.common.js?2f13:1080
(anonymous function) @     vue-resource.common.js?2f13:1008


XMLHttpRequest cannot load https://mywebsite/api/auth/login. 
Response to preflight request doesn't pass access control check: 
No 'Access-Control-Allow-Origin' header is present on the requested 
resource. Origin 'http://localhost:8080' is therefore not allowed 
access. The response had HTTP status code 415.
Run Code Online (Sandbox Code Playgroud)

现在,我已经在Azure中运行了API,并且由于它允许我测试来自Postman的调用,因此我可以肯定在后端正确设置了CORS标头。不太确定Vue和正面。

我在配置文件中有这样的情况:

export const API_ROOT = 'https://mywebsite/api/'
export const AuthResource = Vue.resource(API_ROOT + 'auth{/action}')
Run Code Online (Sandbox Code Playgroud)

比我叫这个动作像:

login: …
Run Code Online (Sandbox Code Playgroud)

javascript azure vue.js vue-resource

7
推荐指数
4
解决办法
4万
查看次数

使用 Strapi 调用初始 Nuxt3 加载时出现 500 错误

在我的应用程序初始加载时,我在index.vue. 模板在这里:

<template>

  <div v-for="(season, index) in seasons" :key="index">
    {{ season.attributes.year }} 
  </div>
    
</template>
<script setup>
  const { find } = useStrapi()
  const {  data: seasons } = await find('seasons')
</script>
Run Code Online (Sandbox Code Playgroud)

第一次加载和刷新时的错误是:

Unhandled error during execution of setup function at
<Index onVnodeUnmounted=fn<onVnodeUnmounted> ref=Ref< undefined > >
Run Code Online (Sandbox Code Playgroud)
GET http://localhost:3000/ 500 (Internal Server Error)
Run Code Online (Sandbox Code Playgroud)

服务器在 localhost 上响应 500。

在我消除错误并从错误状态重新路由到“/”后,我看到了数据,这是刷新和首次加载问题。

我的猜测是该useStrapi函数必须在 onMounted 或类似的东西上被触发?(但如果可能的话,我希望它由服务器端处理)

这可能也会有帮助。我的nuxt.config.ts

export default defineNuxtConfig({
    modules: [
        '@nuxtjs/strapi'
    ],
    strapi: {
        url: process.env.STRAPI_URL || 'http://localhost:1337',
        prefix: …
Run Code Online (Sandbox Code Playgroud)

strapi nuxt.js vuejs3 nuxt-strapi nuxtjs3

4
推荐指数
1
解决办法
2146
查看次数