File tree Expand file tree Collapse file tree 1 file changed +101
-4
lines changed Expand file tree Collapse file tree 1 file changed +101
-4
lines changed Original file line number Diff line number Diff line change 11import { createApp } from "https://unpkg.com/vue@3.0.7/dist/vue.esm-browser.js" ;
22
3- const template = `
4- <p>Hello, {{ name }}!</p>
5- `
3+ const Counter = {
4+ template : `
5+ <div id="counter">
6+ Counter: {{ counter }}
7+ </div>
8+ ` ,
9+ data ( ) {
10+ return {
11+ counter : 0 ,
12+ } ;
13+ } ,
14+ mounted ( ) {
15+ setInterval ( ( ) => {
16+ this . counter ++ ;
17+ } , 1000 ) ;
18+ } ,
19+ } ;
20+
21+ const EventHandling = {
22+ data ( ) {
23+ return {
24+ message : "Hello Vue.js!" ,
25+ } ;
26+ } ,
27+ methods : {
28+ reverseMessage ( ) {
29+ this . message = this . message . split ( "" ) . reverse ( ) . join ( "" ) ;
30+ } ,
31+ } ,
32+ template : `
33+ <div id="event-handling">
34+ <p>{{ message }}</p>
35+ <button v-on:click="reverseMessage">Reverse Message</button>
36+ </div>
37+ ` ,
38+ } ;
39+
40+ const TwoWayBinding = {
41+ data ( ) {
42+ return {
43+ message : "Hello Vue!" ,
44+ } ;
45+ } ,
46+ template : `
47+ <div id="two-way-binding">
48+ <p>{{ message }}</p>
49+ <input v-model="message" />
50+ </div>
51+ ` ,
52+ } ;
53+
54+ const TodoItem = {
55+ props : [ "todo" ] ,
56+ template : `<li>{{ todo.text }}</li>` ,
57+ } ;
58+
59+ const TodoList = {
60+ components : { TodoItem } ,
61+ data ( ) {
62+ return {
63+ groceryList : [
64+ { id : 0 , text : "Vegetables" } ,
65+ { id : 1 , text : "Cheese" } ,
66+ { id : 2 , text : "Whatever else humans are supposed to eat" } ,
67+ ] ,
68+ } ;
69+ } ,
70+ template : `
71+ <div id="todo-list-app">
72+ <ol>
73+ <todo-item
74+ v-for="item in groceryList"
75+ v-bind:todo="item"
76+ v-bind:key="item.id"
77+ ></todo-item>
78+ </ol>
79+ </div>
80+ ` ,
81+ } ;
682
783const app = createApp ( {
84+ components : {
85+ Counter,
86+ EventHandling,
87+ TwoWayBinding,
88+ TodoList,
89+ } ,
890 data ( ) {
991 return {
1092 name : "developer" ,
1193 } ;
1294 } ,
13- template,
95+ template : `
96+ <h2>Greeting</h2>
97+ <p>Hello, {{ name }}!</p>
98+
99+ <h2>Counter</h2>
100+ <Counter></Counter>
101+
102+ <h2>Event handling</h2>
103+ <EventHandling></EventHandling>
104+
105+ <h2>Two-way binding</h2>
106+ <TwoWayBinding></TwoWayBinding>
107+
108+ <h2>Todo list</h2>
109+ <TodoList></TodoList>
110+ ` ,
14111} ) ;
15112
16113app . mount ( "#app" ) ;
You can’t perform that action at this time.
0 commit comments