Vue detect whether the current mode in mock
1. declare global variables in main.js in:
Vue from Import 'VUE' / * global variables * / var global_variable = { isMockMode: mock mode to false // if (true: yes; false: NO) } Vue.prototype.GLOBAL_VARIABLE = global_variable // introduced mockjs IF (process.env === .NODE_ENV 'Development') { the require ( './ mock.js') // if mode mock: is Vue.prototype.GLOBAL_VARIABLE.isMockMode = to true }
2. In vue component:
IF (this.GLOBAL_VARIABLE.isMockMode) { // mode processing in mock } {else processing in non mock mode // }