vue中使用Class

class Person{

constructor(){

this.name="liu";

this.age = 12;

}

//这里不需要function 否则报错

getName() {

return this.name;

}

getAge() {

return this.age;

}

setName(name){

this.name = name;

}

setAge(age){

this.age = age;

}

}

export default Person;

使用实例:

testClassClick(){

let person = new Person();

console.log(person.getAge() + ":" + person.getName())

person.setAge(20);

person.setName('345464');

console.log(person.getAge() + ":" + person.getName())

},

你可能感兴趣的:(ElemntUI,vue.js,javascript,前端)