export default [
{
writer : '아이린',
title: '레드벨벳',
content:'1'
},
{
writer : '슬기',
title: '레드벨벳',
content:'2'
},
{
writer : '웬디',
title: '레드벨벳',
content:'3'
},
]
<template>
<div>
<table>
<tr>
<td>제목</td>
<td>컨텐츠</td>
<td>순서</td>
</tr>
<tr v-for="(item,index) in data" :key="index">
<td>{{ item.title }}</td>
<td>{{ item.content }}</td>
<td>{{ item.idx }}</td>
</tr>
</table>
</div>
</template>
<script>
import data2 from "@/data2"
//골뱅이는 무조건 src부터 시작하게 해준다.
export default {
name:'Read',
data(){
return{
data: data2,
}
}
}
</script>
<template>
<div>
<input v-model="title" placeholder="제목을 입력하세요/">
<textarea v-model="content" placeholder="내용을 입력하세요"/>
<input v-model="idx" placeholder="순서을 입력하세요"/>
<button @click="write">등록하기</button>
</div>
</template>
<script>
import data2 from "@/data2";
export default {
name:"create",
data(){
return{
title:"",
content:"",
idx:"",
data : data2
}
},
methods:{
write(){
this.data.push({
title:this.title,
content:this.content,
idx:this.idx
})
this.$router.push("/");
}
}
}
</script>
<router-view>
라우터로 설정한 페이지를 이 위치에 보여준다.
const router = new VueRouter({
mode:'history',
routes:[
{
path:'/',
name:'Home',
component:'HomeComponent'
},
{
path:'/about',
name:'about',
component:'aboutComponent'
},
]
})
<router-link :to="/">Home<router-link>
<router-link :to="/about">About<router-link>
//template
<button @click="clickEvent">홈으로 이동하기</button>
methods:{
clickEvent(){
this.$router.push('/')
}
}
https://joshua1988.github.io/web-development/vuejs/v-model-usage/