admin管理员组文章数量:1279119
Code:
<v-btn large color="green" @click="function">
<v-icon>star</v-icon> Add
</v-btn>
Is there a solution in Vue or is it also possible via JavaScript?
Code:
<v-btn large color="green" @click="function">
<v-icon>star</v-icon> Add
</v-btn>
Is there a solution in Vue or is it also possible via JavaScript?
Share Improve this question edited May 12, 2019 at 17:41 Dan Is Fiddling By Firelight 6,06118 gold badges80 silver badges131 bronze badges asked Jul 1, 2018 at 19:47 lannenerelannenere 691 gold badge2 silver badges5 bronze badges3 Answers
Reset to default 8You can hide a button using the vue onClick
-event v-on:click
.
v-on:click="isHidden = true"
The attribute isHidden
can be set to "true" so that the text or a button gets invisible if v-if="!isHidden"
is added to the element of your choice.
Have a look at this easy snippet:
var myApp = new Vue({
el: '#myApp',
data: {
isHidden: false
}
})
<script src="https://cdn.jsdelivr/npm/[email protected]/dist/vue.js"></script>
<div id="myApp">
<button v-on:click="isHidden = true">Hide text</button>
<button v-on:click="isHidden = !isHidden">Toggle text</button>
<h1 v-if="!isHidden">Hide me</h1>
</div>
Hide the button onClick is possible using this code:
var myApp = new Vue({
el: '#myApp',
data: {
isHidden: false
}
})
<script src="https://cdn.jsdelivr/npm/[email protected]/dist/vue.js"></script>
<div id="myApp">
<button v-if="!isHidden" v-on:click="isHidden = true">Hide text</button>
</div>
<script src="https://cdn.jsdelivr/npm/[email protected]/dist/vue.js"></script>
<div id="app">
<button v-if="btn" @click="toggle">Press to Hide This Button</button>
</div>
Script
var app = new Vue({
el: '#app',
data: {
btn: true
},
methods: {
toggle() {
this.btn = false;
}
}
})
something like this should work. if btn is true, the button will be displayed. if the button is pressed, the toggle function is triggered, btn is changed to false. the button is only shown if btn is true.
what you can do is to use css to add a class to the element. Front there you can now hide the element using css rules.
an example can be passing the state of the element (that is to hide or to show as an attribute to your ponent when clicked)
eg
<v-btn large color="green" @click="function">
<v-icon>star</v-icon> Add
</v-btn>
to
<v-btn large color="green" @click="function" v-bind"hide = true">
<v-icon>star</v-icon> Add
</v-btn>
then you can now use the variable in your vue ponent to know if you need to show or hide. That's all
本文标签: javascriptHow to hide a button in Vue after it got clickedStack Overflow
版权声明:本文标题:javascript - How to hide a button in Vue after it got clicked? - Stack Overflow 内容由网友自发贡献,该文观点仅代表作者本人, 转载请联系作者并注明出处:http://www.betaflare.com/web/1741250663a2365726.html, 本站仅提供信息存储空间服务,不拥有所有权,不承担相关法律责任。如发现本站有涉嫌抄袭侵权/违法违规的内容,一经查实,本站将立刻删除。
发表评论