-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathpushing_data_to_array.html
More file actions
66 lines (56 loc) · 1.86 KB
/
Copy pathpushing_data_to_array.html
File metadata and controls
66 lines (56 loc) · 1.86 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
<!DOCTYPE html>
<html>
<head>
<meta charset="utf-8">
<title></title>
<script src="https://unpkg.com/vue@2.4.2"></script>
</head>
<body>
<div id="root">
<ul>
<li v-for="(name, index) in names">index = {{index}} - value = {{name}}</li>
</ul>
<!-- Using Vue Js -->
<input type="text" placeholder="enter name" id="inp" v-model="input" @keyup.13="addNewName">
<button type="button" v-on:click="addNewName">Add By Using Vuejs</button>
<!-- Using Js -->
<button type="button" onclick="AddName()">Add By Using JS</button>
</div>
<script>
var app = new Vue({
el: "#root",
data:{
names:["Marwan","Jon","Doe","Yousif"],
input:"",
},
methods: {
addNewName:function () {
// alert(this.input);
if(this.input == ''){
alert("pleas, enter something");
}
else{
this.names.push(this.input);
this.input = '';
}
},
},
// created: function() {
// console.log("hh");
// },
});
// if i want to use function outside of vue instance
function AddName() {
var entered_name = document.getElementById("inp");
if(entered_name.value == ''){
alert("pleas, enter something");
}
else{
app.names.push(entered_name.value);
entered_name.value = '';
}
}
</script>
</body>
</html>
<!-- vue js وراها عدنة العملية نفسهه باستخدام jsللارري من خلال ال push هنا تعلمنة شون نسوي -->