export default class和定义类class的使用

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')
}

打印显示
在这里插入图片描述

  • 1
    点赞
  • 4
    收藏
    觉得还不错? 一键收藏
  • 0
    评论
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值