zoukankan      html  css  js  c++  java
  • nuxt跨域

    根据nuxt官方文档提供的axios module

    安装:

    npm install @nuxtjs/axios @nuxtjs/proxy --save

    nuxt.config.js

      modules: [
        '@nuxtjs/axios','@nuxtjs/proxy'
      ],
      axios: {
          proxy: true, // 表示开启代理
          prefix: '/api/channel', // 表示给请求url加个前缀 /api
          credentials: true // 表示跨域请求时是否需要使用凭证
      },
      proxy: {
        '/api': {
          target: 'http://47.94.142.215:8082', // 目标接口域名
          changeOrigin: true, // 表示是否跨域
          pathRewrite: {
            '^/api': '/', // 把 /api 替换成 /
          }
        }
      },
      build: {
        transpile: [/^element-ui/],
    
        /*
        ** You can extend webpack config here
        */
        extend(config, ctx) {
        },
        vendor: ['axios'] //为防止重复打包
      }
    

    主要是增加了这四处

     index.vue

      mounted () {
        this.$axios.post('/admin/query/list')
          .then(res => {
            console.log(res)
          })
          .catch(e => {
            console.log(e)
          })
      }
  • 相关阅读:
    Matrix Chain Multiplication[HDU1082]
    Color a Tree[HDU1055]
    Piggy-Bank[HDU1114]
    Catching Fish[HDU1077]
    用单位圆覆盖尽量多的点
    LianLianKan[HDU4272]
    Travelling
    求多边形面积
    方格取数(1)
    Pebbles
  • 原文地址:https://www.cnblogs.com/wang715100018066/p/10655457.html
Copyright © 2011-2022 走看看