Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

How to set HTTP header in vue-cli?

I want to set custom header in vue-cli.

The version of vue is 2.5.2.

I tried in main.js:

import Vue from 'vue'
import App from './App'
import router from './router'

Vue.config.productionTip = false
Vue.http.headers.common['Cache-Control'] = 'no-cache, no-store, must-revalidate'

/* eslint-disable no-new */
new Vue({
  el: '#app',
  router,
  template: '<App/>',
  components: { App }
})

But it returns:

Uncaught TypeError: Cannot read property 'headers' of undefined
like image 211
Jeongyong Lee Avatar asked Oct 21 '25 12:10

Jeongyong Lee


1 Answers

You can use the devServer option of your vue.config.js which just proxies it to webpack

To set headers:

devServer: {
   headers: { "Cache-Control": "no-cache, no-store, must-revalidate" }
}
like image 136
Tofandel Avatar answered Oct 23 '25 06:10

Tofandel