账号密码登录
微信安全登录
微信扫描二维码登录

登录后绑定QQ、微信即可实现信息互通

手机验证码登录
找回密码返回
邮箱找回 手机找回
注册账号返回
其他登录方式
分享
  • 收藏
    X
    Vue: 创建的实例中调用函数为什么不用加前缀methods?
    38
    0
    //html
    <div id="app">
      <p>{{ count }}</p>
      <p>
        <button @click="increment">+</button>
        <button @click="decrement">-</button>
      </p>
    </div>
    //js
    // make sure to call Vue.use(Vuex) if using a module system
    
    const store = new Vuex.Store({
      state: {
        count: 0
      },
      mutations: {
          increment: state => state.count++,
        decrement: state => state.count--
      }
    })
    
    new Vue({
      el: '#app',
      computed: {
        count () {
            return store.state.count
        }
      },
      methods: {
        increment () {
          store.commit('increment')
        },
        decrement () {
            store.commit('decrement')
        }
      }
    })

    在以上代码中,

    <button @click="increment">+</button>
    <button @click="decrement">-</button>

    为什么不是methods.increment()?

    0
    打赏
    收藏
    点击回答
        全部回答
    • 0
    更多回答
    扫一扫访问手机版
    • 回到顶部
    • 回到顶部