mylinx

晚上闲着无事, 然后看了阮老师的es6 的类用法,包括继承。 然后, 想着在vue中怎么使用class 。

1. 定义一个 classmodel.js 文件。 里面包含如下代码:

2.接着, 在vue 页面使用。 

先导入  import * as point from \'@/api/classmodel\'  

接着: 

point.Point.hello();
point.PointA.hello1();
 
因为我定义的是静态方法, 所以不需要 new  就可以直接使用里面的静态方法。 
 
 
比如: 我在 Point 类中加入如下方法
setParam() {
  return \'123\';
}
 
当你要使用的时候, 就必须  const p =new point.Point();
p.setParam();
 
 
 
3.总结。  如果做过后端的话, 其实使用很容易理解。 上述例子包含几个知识点。 继承、静态函数、构造器。
 
 
 

 

分类:

技术点:

相关文章:

  • 2021-08-29
  • 2022-12-23
  • 2021-11-15
  • 2021-09-01
  • 2021-08-02
  • 2022-12-23
  • 2021-06-15
  • 2021-11-03
猜你喜欢
  • 2021-12-21
  • 2022-12-23
  • 2021-05-14
  • 2021-12-27
  • 2021-12-05
  • 2022-12-23
  • 2022-12-23
相关资源
相似解决方案