代码
提交代码
<!DOCTYPE html> <html lang="en"> <head> <meta charset="UTF-8"> <meta name="viewport" content="width=device-width, initial-scale=1.0"> <meta http-equiv="X-UA-Compatible" content="ie=edge"> <title>Document</title> </head> <body> <div id="app"> <div> <button>我是添加按钮,我一直在</button> </div> <div> <button id="show" v-show="deleteButton">我是删除按钮,我通过v-show控制显隐</button> <button v-on:click="deleteButton = true">设置显示</button> <button v-on:click="deleteButton = false">设置隐藏</button> </div> <div> <button id="if" v-if="editButton">我是修改按钮,我通过v-if控制显隐</button> <button v-on:click="editButton = true">设置显示</button> <button v-on:click="editButton = false">设置隐藏</button> </div> </div> </body> <script src="https://unpkg.com/vue/dist/vue.js"></script> <script type="text/javascript"> var vm = new Vue({ el: '#app', data() { return { deleteButton: true, editButton: true } } }) </script> </html>
运行结果