vue --- Use Class

When using vue-cli development projects, a lot of class time will be used. Specific use:

the config.js (using classes may also define a constructor)

class config {
    /**
     * 构造函数
     * @param {string} group
     * @param {array} categorys
     */
    constructor(categorys, group) {
        this.categorys = categorys ? categorys : []
        this.group = group
    }
    /**
     * 测试方法
     */
    testPrint(){
        return "bbbbbbbbbbbbbbb";
    }
}
export default new config()

Specific use:

import config from '@/utils/config'
console.log(config.testPrint());

 

Guess you like

Origin www.cnblogs.com/e0yu/p/11059622.html