Evicce
V2EX  ›  Vue.js

请教一下 Vue.js 中 methods 传函数的两种写法的区别

  •  
  •   Evicce · Jul 4, 2019 · 3211 views
    This topic created in 2525 days ago, the information mentioned may be changed or developed.

    小白初学 vue 时遇到的一个问题, Google 了好久也没有找到答案.代码如下.

    	var app = new Vue({
                el: '#app',
                methods: {
                    f1: function () {
                        console.log('f1');
                    },
                    f2() {
                        console.log('f2');
                    }
                }
            })
    

    此处 f1 与 f2 两种写法有何区别? 望大佬解答.

    3 replies    2019-07-04 16:53:00 +08:00
    wuhaoworld
        1
    wuhaoworld  
       Jul 4, 2019
    没区别,第二种是 es6 写法,更简洁而已
    Garwih
        2
    Garwih  
       Jul 4, 2019
    第二种是第一种的简写,ES6 了解一下
    15651980765
        3
    15651980765  
       Jul 4, 2019
    学 vue 的话最好看下 es6 的语法
    About   ·   Help   ·   Advertise   ·   Blog   ·   API   ·   FAQ   ·   Solana   ·   5905 Online   Highest 6679   ·     Select Language
    创意工作者们的社区
    World is powered by solitude
    VERSION: 93c8b4a0 · 45ms · UTC 06:28 · PVG 14:28 · LAX 23:28 · JFK 02:28
    ♥ Do have faith in what you're doing.