Allenqjy
V2EX  ›  问与答

求教: javascript 对象里面可以只装一个单独方法吗

  •  
  •   Allenqjy · Jan 25, 2022 · 1866 views
    This topic created in 1600 days ago, the information mentioned may be changed or developed.

    初学者求教,今天看到一个 Vue 对象,里面有一个单独方法,对象不都是键值对组成的嘛?为啥可以只有一个单独的方法呢? 就是下面代码里的 created(){}

    代码 demo:

    const app = new Vue({ el: '#app', data: { products: [] },

    created() { fetch('https://api.myjson.com') .then(response => response.json()) .then(json => { this.products = json.products ) })

    5 replies    2022-01-25 13:43:04 +08:00
    zcf0508
        1
    zcf0508  
       Jan 25, 2022
    es6 新语法

    const a = {
    a: function() {
    // 函数 a
    },
    b(){
    // 函数 b
    }
    }
    lancelock
        2
    lancelock  
       Jan 25, 2022
    语法糖而已
    Allenqjy
        4
    Allenqjy  
    OP
       Jan 25, 2022
    @zcf0508 明白了,感谢~
    Allenqjy
        5
    Allenqjy  
    OP
       Jan 25, 2022
    @foolnius 谢谢,我看下
    About   ·   Help   ·   Advertise   ·   Blog   ·   API   ·   FAQ   ·   Solana   ·   2797 Online   Highest 6679   ·     Select Language
    创意工作者们的社区
    World is powered by solitude
    VERSION: 3.9.8.5 · 35ms · UTC 12:03 · PVG 20:03 · LAX 05:03 · JFK 08:03
    ♥ Do have faith in what you're doing.