웹에서 하는 일이 많아졌다
웹 애플리케이션 이라 부름다루는 데이터가 증가
CSR 방식<body>
<div id="app">
<h1>{{ message }}</h1>
<button @click="count++">카운팅 : {{ count }}</button>
</div>
<script src="https://unpkg.com/vue@3/dist/vue.global.js"></script>
<script>
const { createApp, ref } = Vue
const app = createApp({
setup() {
const message = ref('Hello Vue!')
const count = ref(0)
return {
// message: message,
message,
count
}
}
})
app.mount('#app')
</script>

<script src="https://unpkg.com/vue@3/dist/vue.global.js"></script> <script src="https://unpkg.com/vue@3/dist/vue.global.js"></script>
<script>
const { createApp} = Vue
</script> <script src="https://unpkg.com/vue@3/dist/vue.global.js"></script>
<script>
const { createApp} = Vue
const app = createApp({})
</script>```HTML
<div id='app'></div>
<script src="https://unpkg.com/vue@3/dist/vue.global.js"></script>
<script>
const { createApp} = Vue
const app = createApp({})
app.mount('#app')
</script>.value 속성이 있는 ref 객체로 래핑하여 반환하는 함수
ref로 선언된 변수의 값이 변경되면, 해당 값을 사용하는 템플릿에서 자동으로 업데이트
인자는 어떠한 타입도 가능
템플릿의 참조에 접근하려면 setup 함수에서 선언 및 반환 필요
편의상 탬플릿에서 ref를 사용할 때는 .value를 작성할 필요 없음
<script src="https://unpkg.com/vue@3/dist/vue.global.js"></script>
<script>
const { createApp, ref} = Vue
const app = createApp({
setup() {
const message = ref('Hello Vue!')
console.log(message)
console.log(message.value)
return {
message
}
}
})
</script>
const app = createApp({
setup() {
const message = ref('Hello Vue!')
return {
message
}
}
}) <div id ="app">
<h1>{{ message }}</h1>
</div> const app = createApp({
setup() {
const message = ref('Hello Vue!')
return {
message
}
}
})<h1>{{ message.split('').reverse().join('') }} </h1> <div id="app">
<button v-on:click="increment">버튼!!!</button>
</div>
<script src="https://unpkg.com/vue@3/dist/vue.global.js"></script>
<script>
const { createApp, ref } = Vue
const app = createApp({
setup() {
const count = ref(0)
const increment = function () {
count.value++
}
const object = { id: ref(0) }
return {
count,
increment
}
}
})
app.mount('#app')
</script>
<h1>{{ object.id + 1 }}</h1>
<script>
const object = { id: ref(0) }
</script>

<div id="app">
<p>반응형 변수: {{ refValue }}</p>
<p>일반 변수: {{ normalValue }}</p>
<button v-on:click="increment">값 업데이트</button>
</div>
<script src="https://unpkg.com/vue@3/dist/vue.global.js"></script>
<script>
const { createApp, ref } = Vue
const app = createApp({
setup() {
// 일반 변수
let normalValue = 0
// 반응형 변수
const refValue = ref(0)
// const refArray = ref([1, 2, 3, 4])
// refArray.value.push(1)
const increment = function () {
normalValue++
refValue.value++
// console.log(normalValue)
}
return {
normalValue,
refValue,
increment
}
}
})
app.mount('#app')
</script>
