美文网首页
Vue 03方法

Vue 03方法

作者: 昵称啦啦啦 | 来源:发表于2018-12-05 16:41 被阅读0次

methods

用途

  • 事件执行的函数到放在这里执行

代码

new Vue({
  el: "#app",
  template: `
    <div>
      <h1 v-show="isShow">1</h1>
      <h1 v-show="isShow">2</h1>
      <h1 v-show="isShow">3</h1>
      <h1 v-if="isShow">4</h1>
      <button @click="changeIsShow">点我行为更酷</button>
    </div>
  `,
  data: function () {
    return {
      isShow: true
    }
  },
  methods: {
    // key是函数名 value是函数体
    changeIsShow: function () {
      // this 就是 data 函数 return 出去的对象
      // vue帮我们处理的this指向,不是事件对象了
      this.isShow = !this.isShow;
    }
  }
})

相关文章

网友评论

      本文标题:Vue 03方法

      本文链接:https://www.haomeiwen.com/subject/xqswcqtx.html