-
Notifications
You must be signed in to change notification settings - Fork 3
Expand file tree
/
Copy pathvuejs.txt
More file actions
603 lines (479 loc) · 9.87 KB
/
Copy pathvuejs.txt
File metadata and controls
603 lines (479 loc) · 9.87 KB
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
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
263
264
265
266
267
268
269
270
271
272
273
274
275
276
277
278
279
280
281
282
283
284
285
286
287
288
289
290
291
292
293
294
295
296
297
298
299
300
301
302
303
304
305
306
307
308
309
310
311
312
313
314
315
316
317
318
319
320
321
322
323
324
325
326
327
328
329
330
331
332
333
334
335
336
337
338
339
340
341
342
343
344
345
346
347
348
349
350
351
352
353
354
355
356
357
358
359
360
361
362
363
364
365
366
367
368
369
370
371
372
373
374
375
376
377
378
379
380
381
382
383
384
385
386
387
388
389
390
391
392
393
394
395
396
397
398
399
400
401
402
403
404
405
406
407
408
409
410
411
412
413
414
415
416
417
418
419
420
421
422
423
424
425
426
427
428
429
430
431
432
433
434
435
436
437
438
439
440
441
442
443
444
445
446
447
448
449
450
451
452
453
454
455
456
457
458
459
460
461
462
463
464
465
466
467
468
469
470
471
472
473
474
475
476
477
478
479
480
481
482
483
484
485
486
487
488
489
490
491
492
493
494
495
496
497
498
499
500
501
502
503
504
505
506
507
508
509
510
511
512
513
514
515
516
517
518
519
520
521
522
523
524
525
526
527
528
529
530
531
532
533
534
535
536
537
538
539
540
541
542
543
544
545
546
547
548
549
550
551
552
553
554
555
556
557
558
559
560
561
562
563
564
565
566
567
568
569
570
571
572
573
574
575
576
577
578
579
580
581
582
583
584
585
586
587
588
589
590
591
592
593
594
595
596
597
598
599
600
601
602
603
>>>>>>>> Vue js <<<<<<<<<
--------------------------------------
Keys:
vue3 js:
submit form, validation, props, router
--------------------------------------
Mirroring started
--------------------------------------
--------------------------------------
//Component.vue
<template>
</template>
<script>
export default {
}
</script>
<style>
</style>
---------------------------------------
---------------------------------------
Getting Started:
Install:
npm install -g @vue/cli
# OR
yarn global add @vue/cli
Create a project:
vue create my-project
# OR
vue ui
---------------------------------------
---------------------------------------
>>>>>> Vue Js Form <<<<<<<<<<
<div id="vueRoot">
<form ref="form">
<input name="vitalInformation" v-model="store.vital">
<a href="#" v-on:click="submit">SUBMIT</a>
</form>
</div>
var store = {vital:''};
vm = new Vue({
el : "#vueRoot",
data : {store : store},
methods : {
submit : function(){
this.$refs.form.$el.submit()
}
}
});
this.$refs.submit.click();
...................
data: function(){
return {
name: "",
price: "",
}
},
methods: {
addProduct(e){
e.preventDefault() // it prevent from page reload
// console.log(this.name, this.price);
}
}
<form v-on:submit="addProduct">
<input type="text" v-model="name" placeholder="Product Name" >
<input type="number" v-model="price" placeholder="Price" >
<button type="submit">Add</button>
</form>
this.$refs.form.submit()
this.$refs.submit.click();
...............................
-------------------------------------------------------------------------
-------------------------------------------------------------------------
>>>>>>> Vue js 2 <<<<<<<<<<
<div id="app">
{{ message }}
</div>
var app = new Vue({
el: '#app',
data: {
message: 'Hello Vue!'
}
})
................
<div id="app-2">
<span v-bind:title="message">
Hover your mouse over me for a few seconds
to see my dynamically bound title!
</span>
</div>
var app2 = new Vue({
el: '#app-2',
data: {
message: 'You loaded this page on ' + new Date().toLocaleString()
}
})
......................
<div id="app-3">
<span v-if="seen">Now you see me</span>
</div>
var app3 = new Vue({
el: '#app-3',
data: {
seen: true
}
})
..................
<div id="app-4">
<ol>
<li v-for="todo in todos">
{{ todo.text }}
</li>
</ol>
</div>
var app4 = new Vue({
el: '#app-4',
data: {
todos: [
{ text: 'Learn JavaScript' },
{ text: 'Learn Vue' },
{ text: 'Build something awesome' }
]
}
})
.....................
<div id="app-4">
<ol>
<li v-for="todo in todos">
{{ todo.text }}
</li>
</ol>
</div>
var app4 = new Vue({
el: '#app-4',
data: {
todos: [
{ text: 'Learn JavaScript' },
{ text: 'Learn Vue' },
{ text: 'Build something awesome' }
]
}
})
.....................
-------------------------------------------------------------------------
-------------------------------------------------------------------------
//Vue Form Validation
https://v2.vuejs.org/v2/cookbook/form-validation.html?redirect=true
-------------------------------------------------------------------------
-------------------------------------------------------------------------
>>>>> Vue js 3 <<<<<<<<
import { createApp } from 'vue'
createApp({
data() {
return {
count: 0
}
}
}).mount('#app')
<div id="app">
<button @click="count++">
Count is: {{ count }}
</button>
</div>
............................
//Single-File Components
<script>
export default {
data() {
return {
count: 0
}
}
}
</script>
<template>
<button @click="count++">Count is: {{ count }}</button>
</template>
<style scoped>
button {
font-weight: bold;
}
</style>
.............................
>>>>>>>> Vue Js Form <<<<<<<<<<<<<
npm run serve
<template>
<h1>User Form</h1>
<form
id="app"
@submit="checkForm"s
+
action="https://vuejs.org/"
method="post"
>
<p v-if="errors.length">
<b>Please correct the following error(s):</b>
<ul>
<li v-for="error in errors" v-bind:key='error'>{{ error }}</li>
</ul>
</p>
<p>
<label for="name">Name</label>
<input
id="name"
v-model="name"
type="text"
name="name"
>
</p>
<p>
<label for="age">Age</label>
<input
id="age"
v-model="age"
type="number"
name="age"
min="0"
>
</p>
<p>
<label for="movie">Favorite Movie</label>
<select
id="movie"
v-model="movie"
name="movie"
>
<option>Star Wars</option>
<option>Vanilla Sky</option>
<option>Atomic Blonde</option>
</select>
</p>
<p>
<input
type="submit"
value="Submit"
>
</p>
</form>
</template>
<script>
export default {
data() {
return {
errors: [],
name: null,
age: null,
movie: null
}
},
methods:{
checkForm: function (e) {
if (this.name && this.age) {
return true;
}
this.errors = [];
if (!this.name) {
this.errors.push('Name required.');
}
if (!this.age) {
this.errors.push('Age required.');
}
e.preventDefault();
}
}
}
</script>
// --> Vue Form Validation <--
<template>
<div class="container">
<div class="row">
<div class="col-lg-4">
<div id="result"></div>
</div>
<div class="col-lg-4">
<h1>User Form</h1>
<form id="app" @submit.prevent = "" action="/" method="post">
<p v-if="errors.length">
<ul v-for="error in errors" v-bind:key="error">
<li class="text-danger">{{ error }}</li>
</ul>
</p>
<input id="name" type="text" v-model="name" placeholder="Name" class="form-control" autocomplete="off">
<input id="password" type="text" v-model="password" min="0" placeholder="Password" class="mt-3 form-control" autocomplete="off">
<input id="age" type="submit" value="Submit" class="btn btn-lg btn-success mt-3 form-control">
<button ref="btn" v-on:click="submit()">Submit</button>
</form>
</div>
</div>
</div>
</template>
<script>
export default{
data() {
return{
uname:"ajay",
upass:"ajay123",
name:"",
password:"",
errors:[],
}
},
methods:{
submit: function () {
this.errors = [];
if (this.name && this.password) {
return true;
}
if (!this.name) {
this.errors.push('Name required.')
}
if (!this.password) {
this.errors.push('Password required.')
}
}
},
mounted(){
console.log('hihi')
},
updated(){
//this.$refs.btn.click()
}
}
</script>
---------------------------------------------------------------------
---------------------------------------------------------------------
>>>>>> Vue Js Props <<<<<<<
1. Parent to Child Component
2. Child to Parent Component
............................
1. Parent to Child component
//Parent Component
<template>
<Child :userName=username/>
</template>
<script>
import Child from './components/Child.vue'
export default {
data(){
return {
username:"Ajay Sisaudiya"
}
}
}
</script>
//Child Component
<template>
{{ userName }}
</template>
<script>
export default {
props:['userName'],
data(){
return {
}
}
}
</script>
.............................
2. Child to Parent Component
//Parent Component
<template>
<Form @title="getTitle" />
</template>
<script>
import Form from './components/Form.vue'
export default {
name: 'App',
components: {
Form
},
methods:{
getTitle:function(value){
console.log(value)
}
}
}
</script>
//Child Component
<template>
<button v-on:click="child()" class="btn btn-lg btn-success mt-3 form-control">Child</button>
</template>
<script>
export default{
data() {
return{
title:"This is from child component",
}
},
methods:{
child: function(){
console.log(this.$emit('title',this.title))
}
}
}
</script>
---------------------------------------------------------------------
---------------------------------------------------------------------
---------------------------------------------------------------------
---------------------------------------------------------------------
>>>>>> Vue cli Router <<<<<<<<
//src/main.js
import { createApp } from 'vue'
import App from './App.vue'
import router from './router'
createApp(App).use(router).mount('#app')
//src/router/index.js
import { createRouter, createWebHistory } from 'vue-router'
//import Index from '@/components/Index.vue'
import Form from '@/components/Form.vue'
import Contact from '@/components/Contact.vue'
//import Register from '@/components/Register.vue'
import Child from '@/components/Child.vue'
import Parent from '@/components/Parent.vue'
const routes = [
{
path: '/',
name: 'Form',
component: Form
},
{
path: '/contact',
name: 'Contact',
component: Contact
},
{
path: '/child',
name: 'Child',
component: Child
},
{
path: '/parent',
name: 'Parent',
component: Parent
},
]
const router = createRouter({ history: createWebHistory(), routes })
export default router
//src/App.js
<template>
<div id="nav">
<router-link to="/">Form</router-link> |
<router-link to="/about">Contact</router-link> |
<router-link to="/child">Child</router-link>
</div>
<router-view />
<h1>Vue Js</h1>
<!--<Child />-->
</template>
<script>
import './assets/bootstrap.css'
//import Child from './components/Child.vue'
export default {
name: 'App',
components: {
//Child
}
}
</script>
//src/components
Form.vue,
Child.vue,
Contact.vue
Parent.vue
//Example:
<template>
<h1>Child</h1>
</template>
<script>
export default {
name: 'Child',
props: [],
data(){
return {
}
},
methods: {
}
}
</script>
----------------> End of Vue Router <------------------------------