1. 알림 패키지설치

1
npm install toastr
cs


2. resources/js/bootstrap.js 에 다음을 추가한다.

window.toastr = require('toastr');


resources/sass/app.scss 에 다음을 추가한다.

@import '~toastr/toastr.scss';



3. 토스트객체를 추가한다.


4. 응답메시지는 TaskController에서 추가했었음


5. 글을 작성해보자~


6. 위치변경하기


toastr: toastr.options = {"positionClass" : "toast-top-full-width"}


7. 확인 (토스트메시지가 중앙으로 이동했다.)

https://github.com/CodeSeven/toastr


8. createTask, updateTask, deleteTaks 에 넣어준다.

toastr.success(response.data.message);




'라라벨 > laravel vue crud' 카테고리의 다른 글

14. 전체소스  (0) 2020.02.28
12. 로더피처 적용하기  (0) 2020.02.28
11. 글작성 후 데이터가 남는 문제 해결  (0) 2020.02.28
10. Delete  (0) 2020.02.28
9. update  (0) 2020.02.28

1. 공개폴더(public)에 images/loder1.gif 파일을 넣는다.


2. 이미지를 삽입하고  flase


3. 로더가 적용될 메서드에 ture 작성한다.


4. 템플릿안에 보일 위치에 image 바인딩을 한다.

<template>
<div>

<div>
<img :src="image" alt="">
</div>


5. 확인


6. 수정

<template>
<div>

<div v-if="!loading">
<img class="rounded mx-auto d-block" :src="image" alt="loder">
</div>

<div v-else>
생략...
</div>


'라라벨 > laravel vue crud' 카테고리의 다른 글

14. 전체소스  (0) 2020.02.28
13. 토스트 알림기능만들기  (0) 2020.02.28
11. 글작성 후 데이터가 남는 문제 해결  (0) 2020.02.28
10. Delete  (0) 2020.02.28
9. update  (0) 2020.02.28

글작성 후 다시 글작성할때 기존 데이터가 남아있는 것을 볼 수 있다.


1. resetData()메서드를 만들어준다.


//리셋데이터 호출
resetData(){

this.task.name = '',
this.task.body = ''
}


2. 만들 데이터를 모달창 닫기전에 넣어주면 된다.


3. 확인


'라라벨 > laravel vue crud' 카테고리의 다른 글

13. 토스트 알림기능만들기  (0) 2020.02.28
12. 로더피처 적용하기  (0) 2020.02.28
10. Delete  (0) 2020.02.28
9. update  (0) 2020.02.28
8. 유효성 검사  (0) 2020.02.27

1. 사진과 같은 부분에 deleteTask 매개변수받는 메서드를 만들어준다


2. 버튼클릭이벤트에 해당메서드를 삽입한다.

<button @click="deleteTask(index)" class="btn btn-danger">Delete</button>


3. delete 메서드 삭제 로직

deleteTask(index){

let confirmBox = confirm("정말로 삭제 하시겠습니까?");

if(confirmBox == true){

axios.delete(this.uri + this.tasks[index].id)
.then(response=>{

this.$delete(this.tasks, index);
}).catch(error=>{

console.log("Could not delete for some reason");

})
}

},


4. 확인


'라라벨 > laravel vue crud' 카테고리의 다른 글

12. 로더피처 적용하기  (0) 2020.02.28
11. 글작성 후 데이터가 남는 문제 해결  (0) 2020.02.28
9. update  (0) 2020.02.28
8. 유효성 검사  (0) 2020.02.27
7. Database Modal Create  (0) 2020.02.27

1. TaskComponent.vue

create modal을 복사 후 붙여넣기 한 다음 수정해서 사용한다.


2. methods:{} 에 업데이트 모달창이벤트메서드를 만들어준다.

//업데이트 모달창 오픈
loadUpdateModal(){

},


3. Edit 버튼에 이벤트메서드호출을 등록한다.

<button @click="loadUpdateModal" class="btn btn-info">Edit</button>


4. new_update_task[] 배열을 만들어준다.

export default {
data() {
return {
task: {
name: "",
body: ""
},

tasks: [],

uri: "http://laravelvuecrud.test/tasks/",
errors: [],
new_update_task:[]

};
},



5. 에러배열을 삽입하고, 모달창 오픈, 해당버튼의 인덱스를 가져온다.

//업데이트 모달창 오픈
loadUpdateModal(index){

this.errors = [];

$("#update-modal").modal("show")

this.new_update_task = this.tasks[index];
},


6. v-model을 수정해준다.

<div class="form-group">
<label for="name">Name</label>
<input v-model="new_update_task.name" type="text" id="name" class="form-control">
</div>


<div class="form-group">
<label for="description">Description</label>
<input v-model="new_update_task.body" type="text" id="description" class="form-control">
</div>


7. updateTask 메서드를 작성한다.


테스트 코드

updateTask(){
console.log(this.new_update_task.name);
},


8. 브라우저에서 확인



9. 최종 업데이트 로직

updateTask() {
axios
.patch(this.uri + this.new_update_task.id, {
name: this.new_update_task.name,
body: this.new_update_task.body
})
.then(response => {
//실행후 모달 닫는 로직
$("#update-modal").modal("hide");
})
.catch(error => {
//에러처리
this.errors = [];

if (error.response.data.errors.name) {
this.errors.push(error.response.data.errors.name[0]);
}

if (error.response.data.errors.body) {
this.errors.push(error.response.data.errors.body[0]);
}
});
},


10. 브라우저 실행


'라라벨 > laravel vue crud' 카테고리의 다른 글

11. 글작성 후 데이터가 남는 문제 해결  (0) 2020.02.28
10. Delete  (0) 2020.02.28
8. 유효성 검사  (0) 2020.02.27
7. Database Modal Create  (0) 2020.02.27
6. Databases Data 불러오기  (0) 2020.02.27

1. uri 아래에 에러배열을 만들어준다.

uri: "http://laravelvuecrud.test/tasks/",
errors: []


2. catch 부분을 작성해준다.

//데이터 삽입하기
createTask(){

axios.post(this.uri, {name: this.task.name, body: this.task.body }).then(response=>{

this.tasks.push(response.data.task);
$("#create-modal").modal("hide");

}).catch(error=>{
//에러처리

this.errors = [];

if(error.response.data.errors.name){
this.errors.push(error.response.data.errors.name[0]);
}

if(error.response.data.errors.body){
this.errors.push(error.response.data.errors.body[0]);
}

});

},


3. 모달 body아래에 에러메시지 부분을 만들어준다.

<div class="modal-body">

<div class="alert alert-danger" v-if="errors.length > 0">
<ul>
<li v-for="error in errors" >{{error}}</li>
</ul>
</div>


4. 브라우저에서 확인해보자


'라라벨 > laravel vue crud' 카테고리의 다른 글

10. Delete  (0) 2020.02.28
9. update  (0) 2020.02.28
7. Database Modal Create  (0) 2020.02.27
6. Databases Data 불러오기  (0) 2020.02.27
5. TaskComponent 템플릿변경  (0) 2020.02.27

1. 모달 적용

https://getbootstrap.com/docs/4.4/components/modal/



2. Modal 설정

<!-- Create Modal -->
<div
class="modal fade"
id="create-modal"
data-backdrop="static"
tabindex="-1"
role="dialog"
aria-labelledby="staticBackdropLabel"
aria-hidden="true"
>
<div class="modal-dialog" role="document">
<div class="modal-content">
<div class="modal-header">
<h5 class="modal-title" id="staticBackdropLabel">Create Modal</h5>
<button type="button" class="close" data-dismiss="modal" aria-label="Close">
<span aria-hidden="true">&times;</span>
</button>
</div>
<div class="modal-body">

<h1>MODAL WORKS</h1>

</div>
<div class="modal-footer">
<button type="button" class="btn btn-secondary" data-dismiss="modal">Close</button>
<button type="button" class="btn btn-primary">Understood</button>
</div>
</div>
</div>
</div>


3. 3번째줄 버튼에 이벤트메서드를 호출등록한다.

<button @click="createModal" class="btn btn-primary btn-block">Add New Task</button>


4. methods에 createModal()메서드를 정의한다. 클릭시 모달창이 오픈되게 한다.

methods: {

createModal(){
$("#create-modal").modal("show")
},

loadTasks() {
axios.get(this.uri).then(response => {
this.tasks = response.data.tasks;
});
}
},


5. methods에 createTask()메서드를 정의한다.

//데이터 삽입하기
createTask(){
console.log(this.task.name);

},


6. 버튼에 메서드 호출을 등록한다.

<button @click="createTask" type="button" class="btn btn-primary">Understood</button>


7. Modal Body에 글등록 양식을 만들어준다.

<div class="modal-body">

<div class="form-group">
<label for="name">Name</label>
<input v-model="task.name" type="text" id="name" class="form-control">
</div>

<div class="form-group">
<label for="description">Description</label>
<input v-model="task.body" type="text" id="description" class="form-control">
</div>

</div>


8. 브라우저에서 글제목을 작성하고 요청을 보내본다.


9. 데이터삽입하는 소스작성

//데이터 삽입하기
createTask(){

axios.post(this.uri, {name: this.task.name, body: this.task.body }).then(response=>{

this.tasks.push(response.data.task);
$("#create-modal").modal("hide");

}).catch(error=>{

console.log(error);

})

},


글이 작성되는지 확인해보자


'라라벨 > laravel vue crud' 카테고리의 다른 글

9. update  (0) 2020.02.28
8. 유효성 검사  (0) 2020.02.27
6. Databases Data 불러오기  (0) 2020.02.27
5. TaskComponent 템플릿변경  (0) 2020.02.27
4. Vue 설정 component 생성, 등록  (0) 2020.02.27

1. TaskComponent.vue

<template>
<div>
<button class="btn btn-primary btn-block">Add New Task</button>

<table class="table" v-if="tasks">
<thead>
<tr>
<th>id</th>
<th>Name</th>
<th>Body</th>
</tr>
</thead>

<tbody>
<tr v-for="(task, index) in tasks">
<td>{{index + 1}}</td>
<td>{{task.name}}</td>
<td>{{task.body}}</td>
<td>
<button class="btn btn-info">Edit</button>
</td>
<td>
<button class="btn btn-danger">Delete</button>
</td>
</tr>
</tbody>
</table>
</div>
</template>

<script>
export default {

data() {
return {
task: {
name: "",
body: ""
},

tasks: [],

uri: "http://laravelvuecrud.test/tasks/"
};
},

methods: {
loadTasks() {
axios.get(this.uri).then(response => {
this.tasks = response.data.tasks;
});
}
},

mounted() {
this.loadTasks();
}
};
</script>



+ Recent posts