<body> <div id="root"> <h2>{{name}}</h2> <hr> <school></school> <hr> <student></student> <hr> <!-- <h2>Student name: {{name}}</h2> <h2>Student age: {{age}}</h2> --> </div> <div id="root2"> <hello></hello> </div> <script> Vue.config.productionTip = false; //Create school component//el:'#root' //When defining a component, be sure not to write the el configuration item, because ultimately all components will be managed by a vm, which will decide which container to serve const school = Vue.extend({ template: ` <div> <h2>School name: {{schoolName}}</h2> <h2>School address: {{address}}</h2> <button @click="showName">Click me to show the school name</button> </div> `, data() { return { schoolName: 'Second Middle School', address: 'Beijing', } }, methods: { showName() { alert(this.schoolName) } } }) //The first step: create components //Create student components const student = Vue.extend({ template: ` <div> <h2>Student name: {{name}}</h2> <h2>Student age: {{age}}</h2> </div> `, data() { return { name: 'Xiao Wang', age: 20, } } }) //Create vm new Vue({ el: '#root', data: { name: 'Hello, World! ' }, //Step 2: Register components (local registration) components: school, student } }) const hello = Vue.extend({ template: ` <div><h2>Hello! Student Wang</h2></div> ` }) Vue.component('hello', hello) new Vue({ el: '#root2' }) </script> </body> SummarizeThis article ends here. I hope it can be helpful to you. I also hope you can pay more attention to more content on 123WORDPRESS.COM! You may also be interested in:
|
<<: Simple example of using Docker container
>>: CSS hacks \9 and \0 may not work for hacking IE11\IE9\IE8
People who use virtual machines usually set up sh...
Table of contents Preface LED Trigger Start explo...
Table of contents 0. What is Webpack 1. Use of We...
Table of contents 1. Lock and Latch 2. Repeatable...
1. Download https://dev.mysql.com/downloads/mysql...
<br />What principles should be followed to ...
Table of contents A brief overview of the replica...
Table of contents 1. Technology Selection 2. Tech...
Database read-write separation is an essential an...
Table of contents 1. Introduction 2. Advantages 3...
Table of contents React Fiber Creation 1. Before ...
Table of contents 1. Use closures 2. Use ES6 clas...
Table of contents Overview Checking setTimeout() ...
Table of contents Early creation method Factory P...
Image tag : <img> To insert an image into a ...