import { userLogin } from '@/api/user' export default { name: 'Login', data() { return { user: {} } }, created() { }, methods: { loginBtn() { this.$store.dispatch('user/frontUserLogin', this.user).then(res => { this.$router.push('/') }).catch(err => { this.$message.error(err) }) } } }
时间: 2023-06-18 19:04:11 浏览: 55
这段代码是一个 Vue 组件,主要实现了一个登录页面的功能。其中,使用了 `userLogin` 方法来调用后端 API 进行用户登录。在 `loginBtn` 方法中,调用了 Vuex 中的 `frontUserLogin` 方法来进行登录操作,并且将登录成功后的用户重定向到首页。如果登录失败,则会在页面上显示错误信息。
相关问题
p://127.0.0.1:8085/admin/userLogin' from origin 'http://localhost:8085' has been blocked by CORS policy: Response to preflight request
这是因为浏览器的同源策略(Same-Origin Policy)限制了跨域请求。简单来说,如果你的网站A想要访问网站B的资源,那么B必须允许A进行跨域访问,否则浏览器会阻止这种请求,这就是CORS(Cross-Origin Resource Sharing)策略。在这种情况下,可能需要在B的后端进行一些配置,允许A的域名访问B的资源。具体的解决方法可以在网上查找相关的资料。
response.sendRedirect("../userlogin/login.jsp");无法执行
`response.sendRedirect("../userlogin/login.jsp")` 方法用于将请求重定向到 `../userlogin/login.jsp` 页面。如果该方法不能执行,可能是以下原因之一:
1. 该代码片段没有在 Servlet 中被正确执行。如果该代码片段在 JSP 页面中,则不能使用 `response.sendRedirect()` 方法。在 JSP 页面中,应该使用 `<jsp:forward>` 标签来实现重定向。
2. `../userlogin/login.jsp` 页面不存在或者路径不正确。请检查该页面是否存在,并且相对路径是否正确。
3. 该代码片段被执行的时机不正确。如果该代码片段被执行的时候已经有输出到客户端,则不能使用 `response.sendRedirect()` 方法。在这种情况下,应该使用 `RequestDispatcher` 对象来实现请求转发。
请根据具体情况检查以上三个原因,并进行相应的调整。
相关推荐
![zip](https://img-home.csdnimg.cn/images/20210720083736.png)
![rar](https://img-home.csdnimg.cn/images/20210720083606.png)
![](https://csdnimg.cn/download_wenku/file_type_ask_c1.png)
![](https://csdnimg.cn/download_wenku/file_type_ask_c1.png)
![](https://csdnimg.cn/download_wenku/file_type_ask_c1.png)
![](https://csdnimg.cn/download_wenku/file_type_ask_c1.png)
![](https://csdnimg.cn/download_wenku/file_type_ask_c1.png)
![](https://csdnimg.cn/download_wenku/file_type_ask_c1.png)
![](https://csdnimg.cn/download_wenku/file_type_ask_c1.png)
![](https://csdnimg.cn/download_wenku/file_type_ask_c1.png)
![](https://csdnimg.cn/download_wenku/file_type_ask_c1.png)
![](https://csdnimg.cn/download_wenku/file_type_ask_c1.png)
![](https://csdnimg.cn/download_wenku/file_type_ask_c1.png)
![](https://csdnimg.cn/download_wenku/file_type_ask_c1.png)
![](https://csdnimg.cn/download_wenku/file_type_ask_c1.png)