export default class和定义类class的使用
写法一
1、创建一个类并导出
class win {
getProcessInfo() {
return 123;
}
}
export default new win(); //用的是export default方法,并且导出的时候就已经实例化了
2、在vue文件中引用
<template>
内容部分
</template>
<script>
import win from "引入路径";
export default {
data() {
return {};
},
methods: {
getProcessInfoFn() {
console.log(win.getProcessInfo()); //233
}
}
};
</script>
写法二
1、定义文件
src\components\map\models\Polygon\LuFce.js
// 写法1
export default class LuFace {
constructor() {
this.setAttributes();
}
setAttributes() {
this.id = '';
this.KIND = 0;
this.geometry = {
type: 'Polygon',
coordinates: []
};
this.NAMEGROUP = [{
LANG_CODE: '',
NAME: '',
PHONETIC: '',
NAMEGROUP_ID:0
}];
this.DISPLAY_LEVEL = 0;
this.POI_PID = 0;
this.ADMIN_ID = 0;
this.partition_name = '';
this.SOURCE = 3;
}
}
// 写法2
class LuFace {
constructor() {
this.setAttributes();
}
setAttributes() {
this.id = '';
this.KIND = 0;
this.geometry = {
type: 'Polygon',
coordinates: []
};
this.NAMEGROUP = [{
LANG_CODE: '',
NAME: '',
PHONETIC: '',
NAMEGROUP_ID:0
}];
this.DISPLAY_LEVEL = 0;
this.POI_PID = 0;
this.ADMIN_ID = 0;
this.partition_name = '';
this.SOURCE = 3;
}
}
export default new LuFace()
2、使用文件
import LuFace from '@/components/map/models/Polygon/LuFce';
console.log('789',LuFace);
// 模型数据
const modelConfig = {
"GDB_LuFace": new LuFace() // 对应写法1
"GDB_LuFace": LuFace // 对应写法2
}
let objName = store.state.map.activeLayerId;
let definitionNameType = {
'LU_FACE': 'GDB_LuFace',
};
// 使用方式1
let activeLayerIdList = ['LU_FACE', 'LC_FACE', 'RW_LINK', 'fdb_poi_merge']
if (activeLayerIdList.includes(store.state.map.activeLayerId)) {
console.log('123')
}
// 使用方式2
if (res.data.objName === "LU_FACE" || res.data.objName === "LC_FACE") {
console.log('456')
}
打印显示