Vue 03方法
2018-12-05 本文已影响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;
}
}
})