vue 调用常量的config.js文件
我遇到问题,就是有很多常量需要应用的项目里面.所以需要打算设置一个config.js文件
1.填写config.js 文件
//常量配置 //快递公司名单 对应的页面为: src/pages/other/kuaidi/index.vue export const kdcompanyOptions=[ {value: "shunfeng", label: "顺丰"}, {value: "shentong", label: "申通"}, {value: "zhongtong", label: "中通"}, {value: "yuantong", label: "圆通"}, {value: "debang", label: "德邦"} ]
2.在vue 页面中引用 config.js文件
<template> <d2-container> <template slot="header"> <el-select v-model="const_kd"> <el-option v-for="item in kdcompanyOptions" :key="item.value" :label="item.label" :value="item.value"></el-option> </el-select> </template> content <template slot="footer">foot</template> </d2-container> </template> <script> import { kdcompanyOptions} from "../../config/config"; //引入常量 export default { name: "page_kuaidi", data() { return { const_kd: "", kdcompanyOptions:[] }; }, created: function() { this.kdcompanyOptions=kdcompanyOptions } }; </script>