V2EX = way to explore
V2EX 是一个关于分享和探索的地方
Sign Up Now
For Existing Member  Sign In
Allenqjy
V2EX  ›  问与答

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

  •  
  •   Allenqjy · Jan 25, 2022 · 1788 views
    This topic created in 1566 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   ·   6169 Online   Highest 6679   ·     Select Language
    创意工作者们的社区
    World is powered by solitude
    VERSION: 3.9.8.5 · 51ms · UTC 02:53 · PVG 10:53 · LAX 19:53 · JFK 22:53
    ♥ Do have faith in what you're doing.