查看“︁Node.js/nuxt/跨域”︁的源代码
来自康健生活
←
Node.js/nuxt/跨域
因为以下原因,您没有权限编辑该页面:
您请求的操作仅限属于该用户组的用户执行:
用户
您可以查看和复制此页面的源代码。
== 引言 == <blockquote> <syntaxhighlight lang="bash"> npm install @nuxtjs/axios @nuxtjs/proxy --save </syntaxhighlight></blockquote> {{hc|nuxt.conf.js|<syntaxhighlight lang="javascript"> modules: [ '@nuxtjs/axios', '@nuxtjs/proxy' ], axios: { proxy: true, prefix: '/api', // url 添加前缀 /api credentials: true // 示跨域请求凭证 }, proxy: { '/api': { target: 'http://192.168.1.10:3000', changeOrigin: true, pathRewrite: { '^/api': '/', } } } build: { vendor: ["axios"] } </syntaxhighlight>}} == axios == === 封装 === <syntaxhighlight lang="javascript"> import axios from 'axios' import { userAuth } from "@/utils/auth"; const service = axios.create({ baseURL: 'http://192.168.1.10:3000', timeout: 30000, headers: {'Authorization': 'Bearer ' + userAuth.getToken}, }) export default service</syntaxhighlight>
此页面嵌入的页面:
模板:Hc
(
查看源代码
)
模板:Hc/style.css
(
查看源代码
)
返回
Node.js/nuxt/跨域
。
导航菜单
康健生活
搜索
user-page
通知
user-interface-preferences
个人工具
登录
五一
多读书,多运动,多到远处走走,再看看不一样的世界。