1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 | <!DOCTYPE html> <html lang="en"> <head> <title>Component No1</title> <link rel="stylesheet" href="https://cdnjs.cloudflare.com/ajax/libs/bulma/0.7.1/css/bulma.css"> <style> body{ padding-top:40px; } </style> </head> <body> <div id="root" class="container"> <componentName title="Hello World" body="lorem ipsum dolar sit amet."></componentName> <componentName title="Success" body="creating component by using props on components"></componentName> </div> <script src="https://cdn.jsdelivr.net/npm/vue@2.5.17/dist/vue.js"></script> <script src="component.js"></script> </body> </html> |
In JS
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 | Vue.component('componentName', { props: ['componentProps',], data(){ return{ componentCondition: true, //boolean } }, template: ` <article class="message is-warning" v-show="inVisible"> <div class="message-header"> {{ title }} <button type="button" @click="clickMethod">x</button> </div> <div class="message-body"> {{ body }} </div> </article> `, methods:{ clickMethod(){ this.componentCondition = false; //methods is events+data= result } } }); new Vue({ el:'#root' //div id on html }); |