Nuxt.js代理转发解决跨域问题"/>
15、Nuxt.js代理转发解决跨域问题
nuxt.config.js
export default {...// Modules: /config-modulesmodules: ["@nuxtjs/axios"],axios: {proxy: true, // 开启代理转发prefix: "/api"},// 代理转发proxy: {'/api': {target: "",pathRewrite: { "^/api": "",changeOrigin: true }}},...
}
pages\index.vue
/*** 加载组件之前服务端调用*/async asyncData({ $axios }) {try {let res = await $axios.$get("/test");console.log(res.data)return {res: res?.data};} catch (err) {console.log(err);}},
更多推荐
15、Nuxt.js代理转发解决跨域问题
发布评论