[Vue基础实战]render函数使用-2
参考代码:
<!DOCTYPE html> <html lang="en"> <head> <meta charset="UTF-8"> <meta name="viewport" content="width=device-width, initial-scale=1.0"> <title>render函数演示2</title> <style> .ul-nav li{ list-style: none; float:left; width:100px; text-align: center; background-color: lawngreen; margin:0px 1px; } </style> </head> <body> <div id="app"> 看不见我 </div> <script src="../js/vue.js"></script> <script> var login=Vue.extend({ template:'<h3>登录</h3>' }); const app = new Vue({ el: '#app', data: { }, methods:{ }, render:function(createElement){ const menu_items=["少林","武当","华山","昆仑"]; return createElement('ul',{ class:{'ul-nav':true} },menu_items.map(item=>createElement('li',item)) ); } }); </script> </body> </html>