根據nuxt官方文檔提供的axios modulevue
安裝:webpack
npm install @nuxtjs/axios @nuxtjs/proxy --save
nuxt.config.jsios
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'] //爲防止重複打包 }
主要是增長了這四處web
index.vuenpm
mounted () { this.$axios.post('/admin/query/list') .then(res => { console.log(res) }) .catch(e => { console.log(e) }) }