問題:瀏覽器控制台會輸出warning,提示:ReferenceError: __VUE_OPTIONS_API__, __VUE_PROD_DEVTOOLS__ is not defined.
官方文檔解釋為:
Starting with 3.0.0-rc.3,
esm-bundler
builds now exposes global feature flags that can be overwritten at compile time:
__VUE_OPTIONS_API__
(enable/disable Options API support, default:true
)__VUE_PROD_DEVTOOLS__
(enable/disable devtools support in production, default:false
)The build will work without configuring these flags, however it is strongly recommended to properly configure them in order to get proper tree-shaking in the final bundle. To configure these flags:
- webpack: use DefinePlugin
- Rollup: use @rollup/plugin-replace
- Vite: configured by default, but can be overwritten using the
define
optionNote: the replacement value must be boolean literals and cannot be strings, otherwise the bundler/minifier will not be able to properly evaluate the conditions.
就是在vue@3.0.0-rc.3版本開始,強烈推薦我們設置 __VUE_OPTIONS_API__, __VUE_PROD_DEVTOOLS__ 兩個屬性,
例如使用 DefinePlugin,我們在webpack的plugins中可以這樣設置:
1 new webpack.DefinePlugin({ 2 '__VUE_OPTIONS_API__': true, 3 '__VUE_PROD_DEVTOOLS__': false 4 })
PS: 這里要注意設置的值得是boolean類型!
設置完控制台將不會再提示!
參考文檔: