在我的vue项目中导入常量的最佳实践是什么,在我的例子中,它是一个ENUMS。
我在Vue的实例中添加了这样的解决方案
import { Type } from './models/Type.js'
new Vue({
router,
Type,
render: h => h(App)
}).$mount('#app')但这不起作用
发布于 2019-08-30 15:07:30
const是保留关键字,您可以使用另一个名称,如myConst,并在此tip尝试的基础上:
Vue.prototype.$myConst=4;
new Vue({
router,
render: h => h(App)
}).$mount('#app')使用this.$myConst在应用程序中的任何地方都可以参考它。
// ignore the following two lines, they just disable warnings in "Run code snippet"
Vue.config.devtools = false;
Vue.prototype.$myConst=4444;
new Vue({
el: '#app',
created(){
console.log(this.$myConst)
}
});<link type="text/css" rel="stylesheet" href="//unpkg.com/bootstrap/dist/css/bootstrap.min.css" />
<script src="https://cdnjs.cloudflare.com/ajax/libs/vue/2.5.16/vue.js"></script>
<div id="app" class="container">
<h1>test : {{this.$myConst}}</h1>
</div>
https://stackoverflow.com/questions/57729182
复制相似问题