Although the deer in my heart is old, it is beautiful to collide slowly. I am Lee Dahyun

Front-end QQ group: 981668406 in this attached to my QQ: 2489757828 questions can be discussed together with my Github:Li DaxuanMy personal blog:Li DaxuanMy NPM open Source library:Li Daxuan

My simple book:Li DaxuanMy CSDN:Li DaxuanMy nuggets:Li Daxuan

The class name is the big hump name, Pascal

Let’s start with three files, par file means parent file, and a son file means child file, and the child inherits from the parent. Here’s my code

  1. par.js
export default class Par extends Object {
  constructor(name) {
    super(a);this.name = name;
  }
  get1(num = 0) {
    return 1+ num; }}Copy the code
  1. son.js
import Par from './par';
son classinheritancepar class 
export default class Son extends Par {
  constructor(age) {
    super(a);this.age = age;
  }
  get1(num = 0) {
    const res = super.get1(num);
    // do something
    return res
  }
}
Copy the code
  1. a.html

In fact, son’s method is called, but the addition method is made by the PAR file. Pass 1, return 2, pass 3, return 4… And so on

import Son from './cl/son';

mounted() {
    this.init();
  },
  methods: {
    init() {
      const son = new Son();
      const num = son.get1(1); / / 2
      console.log(num); }},Copy the code