本文實例為大家分享了vue注冊表單的具體代碼,供大家參考,具體內容如下
<!doctype html><html> <head> <meta charset="UTF-8"> <title></title> <script src="js/vue.js"></script> </head> <body> <div id="container"> <p>{{msg}}</p> <my-article></my-article> </div> <script> //要采用組件化的方式來編寫頁面, // 把任何一個可被重用的元素封裝成組件 // everything is component Vue.component("my-title",{ template:`<div> <h1>清風手紙</h1> <h4>原木</h4> </div>` }) Vue.component("my-content",{ //一個就可以用引號或者`` template:'<p>源于純凈,歸于健康</p>' }) Vue.component("my-article",{ //當調用多個組件時要用``符號,而且要用頂層標簽包含 template:` <div> <my-title></my-title> <my-content></my-content> </div> ` }) new Vue({ el:"#container", data:{ msg:"Hello VueJs" } }) </script> </body></html><!doctype html><html> <head> <meta charset="UTF-8"> <title></title> <script src="js/vue.js"></script> </head> <body> <div id="container"> <p>{{msg}}</p> <!--調用根組件 --> <my-form></my-form> </div> <script> //創建組件my-user Vue.component("my-user",{ template:` <label>用戶名:</label> ` }) Vue.component("user-input",{ template:` <input type="text" placeholder="請輸入用戶名"/> ` }) Vue.component("my-pwd",{ template:` <label>密碼:</label> ` }) Vue.component("pwd-input",{ template:` <input type="text" placeholder="請輸入密碼"/> ` }) Vue.component("my-login",{ template:` <button>登錄</button> ` }) Vue.component("my-resign",{ template:` <button>注冊</button> ` }) //復合組件作為根組件名字必須是烤串式的,駝峰的會報錯 Vue.component("my-form",{ //可以用table、form、div等…… template:` <form> <my-user></my-user> <user-input></user-input> <br> <my-pwd></my-pwd> <pwd-input></pwd-input> <br> <my-resign></my-resign> <my-login></my-login> //寫法或者 <my-login/> </form> ` }) new Vue({ el:"#container", data:{ msg:"Hello VueJs" } }) </script> </body></html>
新聞熱點
疑難解答
圖片精選