Vue.js手风琴菜单组件开发实例

小图标是引入font-awesome字体图标库绘制的。效果如下图所示:

Vue.js手风琴菜单组件开发实例

代码:

<!DOCTYPE html> <html lang="en"> <head> <meta charset="UTF-8"> <title>index</title> <link href="https://www.jb51.net/css/font-awesome.min.css"> <link href="https://www.jb51.net/css/index.css"> <script type="text/javascript" src="https://www.jb51.net/lib/vue.min.js"></script> <script type="text/javascript" src="https://www.jb51.net/lib/jquery-1.11.3.min.js"></script> <style> * { margin: 0; padding: 0; } body { padding-top: 100px; } #tabPanel { width: 120px; height: auto; margin: 0 auto; } #tabPanel .item .sildermun ul li { height: 40px; line-height: 40px; list-style: none; } #tabPanel .item .sildermun ul li:hover { background: #ccc; } #tabPanel .item .menutitle { height: 40px; line-height: 40px; text-align: center; background: #ccc; } #tabPanel .item .sildermun { text-align: center; background: #eee; } </style> </head> <body> <div> <slider-item></slider-item> <slider-item></slider-item> <slider-item></slider-item> <slider-item></slider-item> </div> <!--组件模板,也可以使用template标签方式引入模板--> <template> <div> <div> <div @click="toggle()"><i></i>&nbsp;{{parentItem}}</div> <div v-show="status"> <ul> <li v-for="(index,v) in childItems"><i></i>&nbsp;{{v+index}}</li> </ul> </div> </div> </div> </div> </template> <!--组件模板,也可以使用template标签方式引入模板--> </body> </html>

<script> var vue = new Vue({ el: "#tabItem", data: { }, components: { 'slider-item': { template: '#tab', data: function() { return { status: false, parentItem: "父级菜单", childItems: ["子级菜单", "子级菜单", "子级菜单", "子级菜单"] } }, methods: { //切换滑块 toggle: function() { this.status = !this.status; } } } } }); </script>

内容版权声明:除非注明,否则皆为本站原创文章。

转载注明出处:https://www.heiqu.com/wysjzy.html