We read every piece of feedback, and take your input very seriously.
To see all available qualifiers, see our documentation.
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
代码参考:lesson03/01. v-on指令.html
通过v-on指令添加事件,如v-on:click="onClick(1)",表示添加的是click事件,同时传入1作为参数。 v-on:click="onClick(1)"也可以简写为@click="onClick(1)"。
JavaScript:
let vm = new Vue({ el: '#app', // 根元素或挂载点。 data: { num: 1 }, methods: { onClick(add) { this.num = this.num + add }, } })
HTML:
<div id="app"> {{num}} <button v-on:click="onClick(1)">+1</button> </div>
代码参考:/lesson03/02. v-show、v-if指令.html
v-show通过控制样式的display: none;和display: block;,实现显示隐藏。 v-if是直接添加和删除该元素,如果有的元素即使display: none;后还是会对页面效果有影响,建议使用v-if。
let vm = new Vue({ el: '#app', // 根元素或挂载点。 data: { show: true }, methods: { onClick(add) { this.show = !this.show }, } })
<div id="app"> <button v-on:click="onClick()">显示隐藏</button> <div class="box" v-show="show"></div> <div class="box2" v-if="show"></div> </div>
The text was updated successfully, but these errors were encountered:
No branches or pull requests
阅读更多系列文章请访问我的GitHub博客,示例代码请访问这里。
v-on指令
通过v-on指令添加事件,如v-on:click="onClick(1)",表示添加的是click事件,同时传入1作为参数。
v-on:click="onClick(1)"也可以简写为@click="onClick(1)"。
JavaScript:
HTML:
v-show、v-if指令
v-show通过控制样式的display: none;和display: block;,实现显示隐藏。
v-if是直接添加和删除该元素,如果有的元素即使display: none;后还是会对页面效果有影响,建议使用v-if。
JavaScript:
HTML:
The text was updated successfully, but these errors were encountered: