728x90
1. v-text
<!DOCTYPE html>
<html lang="en">
<head>
<meta charset="UTF-8" />
<meta name="viewport" content="width=device-width, initial-scale=1.0" />
<title>Document</title>
<script src="https://cdn.jsdelivr.net/npm/vue@2"></script>
</head>
<body>
<div id="app1">
<p>{{myText}}</p>
<p v-text="myText"></p>
</div>
<script>
new Vue({
el: "#app1",
data: {
myText: "Hello!",
},
});
</script>
</body>
</html>
2. ๋ฐ์ดํฐ ํ์
Vue์์ ๋ฐ์ดํฐํ์ ์ ์ซ์ํ, ๋ฌธ์ํ, Boolean์ด ์๋ค.
<!DOCTYPE html>
<html lang="en">
<head>
<meta charset="UTF-8" />
<meta name="viewport" content="width=device-width, initial-scale=1.0" />
<title>vue ๋ฌธ์ํ example</title>
<script src="https://cdn.jsdelivr.net/npm/vue@2"></script>
</head>
<body>
<div id="app1">
<p>{{ myPrice * 1.08 }}</p>
<p>{{ "์๋
ํ์ธ์~ "+ myName + "๋" }}</p>
<p>{{ myName.substr(0,1) }}</p>
</div>
<script>
new Vue({
el: "#app",
data: {
myPrice: 500, //์ซ์ํ
myName: "ํ๊ธธ๋", //๋ฌธ์ํ
},
});
</script>
</body>
</html>
3. v-on
์ด๋ฒคํธ ์ง์ . ์ฝ์ด๋ก @๋ฅผ ์ฌ์ฉํ ์๋ ์๋ค.
<!DOCTYPE html>
<html lang="en">
<head>
<meta charset="UTF-8" />
<meta name="viewport" content="width=device-width, initial-scale=1.0" />
<title>v-on example</title>
<script src="https://cdn.jsdelivr.net/npm/vue@2"></script>
</head>
<body>
<div id="app1">
<p v-text="value"></p>
<button v-on:click="setValue('1๋ฒ')">1๋ฒ ๋ฒํผ</button>
<button @click="setValue('2๋ฒ')">2๋ฒ ๋ฒํผ</button>
</div>
<script>
new Vue({
el: "#app1",
data: {
value: "ํด๋ฆญํด ๋ณด์ธ์.",
},
methods: {
setValue(str) {
this.value = str + " ํด๋ฆญ";
},
},
});
</script>
</body>
</html>
4. v-bind
์์ฑ์ vue ์ธ์คํด์ค์ ์์ฑ์ด๋ ๋ฉ์๋, JavaScript ๊ตฌ๋ฌธ์ ์ฌ์ฉํ ์ ์๊ฒ ํด์ค๋ค.
<!DOCTYPE html>
<html lang="en">
<head>
<meta charset="UTF-8" />
<meta name="viewport" content="width=device-width, initial-scale=1.0" />
<title>v-bind example</title>
<script src="https://cdn.jsdelivr.net/npm/vue@2"></script>
</head>
<body>
<div id="app1">
<a v-bind:href="url">๋ค์ด๋ฒ</a>
<a :href="getUrl('google')">๊ตฌ๊ธ</a>
</div>
<script>
const app = new Vue({
el: "#app1",
data: { url: "https://www.naver.com" },
methods: {
getUrl: function (name) {
return "https://" + name + ".com";
},
},
});
</script>
</body>
</html>
5. v-model
์๋ฐฉํฅ ๋ฐ์ดํฐ ๋ฐ์ธ๋ฉ
<!DOCTYPE html>
<html lang="en">
<head>
<meta charset="UTF-8" />
<meta name="viewport" content="width=device-width, initial-scale=1.0" />
<title>Document</title>
<title>v-model example</title>
<script src="https://cdn.jsdelivr.net/npm/vue@2"></script>
</head>
<body>
<div id="app1">
<!--v-model์ ์ฌ์ฉํด ํ๋กํผํฐ์ ๊ฐ์ input๊ฐ์ผ๋ก ์ ์ฅ๊ฐ๋ฅ-->
<input type="text" v-model="input_model" placeholder="์ด๋ฆ" />
<p>input model: {{input_model}}</p>
<!--lazy๋ input์ ํฌ์ปค์ค๋ฅผ ๋ค๋ฅธ๊ณณ์ผ๋ก ์ด๋ํ ๋ ํ๋กํผํฐ์ ์ ์ฅํ๋ ๊ธฐ๋ฅ-->
<input type="text" v-model.lazy="input_model2" />
<p>input lazy model : {{input_model2}}</p>
<!--textarea์์๋ v-model ์ฌ์ฉ๊ฐ๋ฅ-->
<textarea v-model="textarea_model"></textarea>
<p>textarea model : {{textarea_model}}</p>
<!--checkbox์์ ์ฌ์ฉ ์์ ์ ์ฅ๋ ํ๋กํผํฐ๋ฅผ v-bind๋ฅผ ํตํด ๋ก์ง ์คํ๊ฐ๋ฅ-->
<input type="checkbox" v-model="checkbox_model" value="awd" />
<button v-bind:disabled="checkbox_model === false">disabled</button>
<p>checkbox model : {{checkbox_model}}</p>
<!--ํ๋กํผํฐ๋ฅผ ๋ฐฐ์ด๋ก ์ ์ธํ๋ฉด value๊ฐ์ ์ ์ฅ-->
<input type="checkbox" v-model="checkbox_model2" value="test1" />
<input type="checkbox" v-model="checkbox_model2" value="test2" />
<p>checkbox model : {{checkbox_model2}}</p>
<!--๋ผ๋์ค ํ๋กํผํฐ ์ ์ฅ-->
<input type="radio" v-model="radio_model" value="test1" />
<input type="radio" v-model="radio_model" value="test2" />
<input type="radio" v-model="radio_model" value="test3" />
<p>radio model : {{radio_model}}</p>
<!--select ํ๋กํผํฐ ์ ์ฅ-->
<select v-model="select_model">
<option>test1</option>
<option>test2</option>
</select>
<p>select model : {{select_model}}</p>
</div>
<script>
const app = new Vue({
el: "#app1",
data: {
input_model: "",
input_model2: "",
textarea_model: "",
checkbox_model: false,
checkbox_model2: [],
radio_model: "",
select_model: "",
},
});
</script>
</body>
</html>
6. v-if
์กฐ๊ฑด๋ฌธ
<!DOCTYPE html>
<html lang="en">
<head>
<meta charset="UTF-8" />
<meta name="viewport" content="width=device-width, initial-scale=1.0" />
<title>v-if example</title>
<script src="https://cdn.jsdelivr.net/npm/vue@2"></script>
</head>
<body>
<div id="app">
<!--๋ฒํผ ํด๋ฆญ์ ํด๋ฆญํ text์ถ๋ ฅ๊ณผ ํด๋ฆญํ ๋ฒํผ ๋นํ์ฑ-->
<button v-bind:disabled="one" v-on:click="oneCheck">one</button>
<button v-bind:disabled="two" v-on:click="twoCheck">two</button>
<button v-bind:disabled="three" v-on:click="threeCheck">three</button>
<p v-if="one">onc click</p>
<p v-else-if="two">two click</p>
<p v-else>three click</p>
</div>
<script>
new Vue({
el: "#app",
data: {
one: false,
two: false,
three: true,
},
methods: {
oneCheck() {
this.one = true;
this.two = false;
this.three = false;
},
twoCheck() {
this.one = false;
this.two = true;
this.three = false;
},
threeCheck() {
this.one = false;
this.two = false;
this.three = true;
},
},
});
</script>
</body>
</html>
7. v-for๋ฐ๋ณต๋ฌธ
<!DOCTYPE html>
<html lang="en">
<head>
<meta charset="UTF-8" />
<meta name="viewport" content="width=device-width, initial-scale=1.0" />
<title>v-for example</title>
<script src="https://cdn.jsdelivr.net/npm/vue@2"></script>
</head>
<body>
<div id="app">
<ul>
<!--arr๋ฐฐ์ด์ ๊ฐ ์์๋ฅผ item์ ๋ด๋๋ค-->
<li v-for="(item, index) in arr" :key="index">{{ item }}</li>
<br />
<!--object์ key๊ฐ๊ณผ value๋ฅผ ๋ถ๋ฌ์ ์ถ๋ ฅ๊ฐ๋ฅ-->
<li v-for="(value, key) in obj" :key="key">{{ key }} : {{ value }}</li>
<br />
<!--objectArray์ item(Object)๋ฅผ ์ถ๋ ฅ-->
<li v-for="(item, index) in objArr" :key="index">
{{ item.a}} : {{ item.b }} : {{ item.c }}
</li>
<br />
<!--์
๋ ฅ๊ฐ์ ์ถ๊ฐ ํ๋ ๊ธฐ๋ฅ-->
<input v-model="num" />
<button v-on:click="add(num)">add</button>
<button v-on:click="deletes()">delete</button>
<li v-for="item in pushArr">{{item}}</li>
</ul>
</div>
<script>
new Vue({
el: "#app",
data: {
arr: ["์จ๋นต", "๋ฉ๋ก ๋นต", "ํฌ๋ก์์ฌ"],
obj: { a: 1, b: 2, c: 3 },
objArr: [
{ a: 1, b: 2, c: 3 },
{ a: 4, b: 5, c: 6 },
],
pushArr: [],
num: 0,
},
methods: {
add(val) {
this.pushArr.push(val);
},
deletes() {
this.pushArr.pop();
},
},
});
</script>
</body>
</html>
https://cjw-awdsd.tistory.com/33
728x90
'๐ป์น(Web)' ์นดํ ๊ณ ๋ฆฌ์ ๋ค๋ฅธ ๊ธ
์ฝ๋ ๋ฆฌํฉํ ๋ง (1) | 2024.12.20 |
---|---|
Spring (0) | 2024.12.02 |
JSP(Jakarta Server Pages), JSTL(JSP Standard Tag Library) (0) | 2024.12.01 |
Servlet (0) | 2024.12.01 |
[๊ณตํตํ๋ก์ ํธ]5์ฃผ์ฐจ: React Openvidu ๊ตฌํ (0) | 2024.08.11 |