How check if Vue is in development mode?

前端 未结 9 701
灰色年华
灰色年华 2021-01-03 18:14

When I run my Vue app, the console shows:

You are running Vue in development mode.
Make sure to turn on production mode when deploying for production.
See mo         


        
9条回答
  •  一生所求
    2021-01-03 19:00

    I usually use:

    if(window.location.href.indexOf("localhost") >= 0) {
      // Development mode    
    }
    

    Or:

    if(window.location.href.indexOf("localhost") < 0) {
      // Production mode    
    }
    

    By just searching for part of the development URL like localhost you don't need to be so specific with the rest of the address. This works anywhere in your project, unlike process.env.NODE_ENV which won't work in the index.html file for example.

提交回复
热议问题