Commit af3fd7ec authored by Bui Duc Tuan's avatar Bui Duc Tuan

call api width axios

parent ca002138
This diff is collapsed.
...@@ -12,8 +12,11 @@ ...@@ -12,8 +12,11 @@
"dependencies": { "dependencies": {
"@fortawesome/fontawesome-svg-core": "^1.3.0", "@fortawesome/fontawesome-svg-core": "^1.3.0",
"@fortawesome/free-solid-svg-icons": "^6.0.0", "@fortawesome/free-solid-svg-icons": "^6.0.0",
"axios": "^0.26.0",
"bootstrap": "^5.1.3", "bootstrap": "^5.1.3",
"vue": "^2.5.11", "vue": "^2.5.11",
"vue-alertify": "^1.1.0",
"vue-axios": "^3.4.1",
"vue-router": "^3.0.1" "vue-router": "^3.0.1"
}, },
"browserslist": [ "browserslist": [
......
...@@ -43,15 +43,38 @@ ...@@ -43,15 +43,38 @@
</template> </template>
<script> <script>
import Vue from "vue";
import VueAlertify from "vue-alertify";
import axios from "axios";
import VueAxios from "vue-axios";
Vue.use(VueAxios, axios);
Vue.use(VueAlertify);
export default { export default {
data: function () { data: function () {
return { return {
tasks: [], tasks: [],
api: [],
}; };
}, },
created: function () { mounted: function () {
if (localStorage.getItem("tasks")) { if (!localStorage.getItem("tasks")) {
this.axios.get("https://dog.ceo/api/breeds/list/all").then((response) => {
let ar = response.data.message.hound;
if (ar.length != 0) {
for (let i = 0; i < ar.length; i++) {
this.task = ar[i];
this.tasks.unshift({
name: this.task,
status: "to-do",
});
}
localStorage.setItem("tasks", JSON.stringify(this.tasks));
}
});
}else{
this.tasks = JSON.parse(localStorage.getItem("tasks")); this.tasks = JSON.parse(localStorage.getItem("tasks"));
} }
}, },
...@@ -61,6 +84,7 @@ export default { ...@@ -61,6 +84,7 @@ export default {
if (confirm("Are you sure you want to delete task?")) { if (confirm("Are you sure you want to delete task?")) {
this.tasks.splice(index, 1); this.tasks.splice(index, 1);
localStorage.setItem("tasks", JSON.stringify(this.tasks)); localStorage.setItem("tasks", JSON.stringify(this.tasks));
this.$alertify.error("Delete task successfully");
} }
}, },
}, },
......
...@@ -27,6 +27,11 @@ ...@@ -27,6 +27,11 @@
</template> </template>
<script> <script>
import Vue from 'vue';
import VueAlertify from 'vue-alertify';
Vue.use(VueAlertify);
export default { export default {
data: function () { data: function () {
return { return {
...@@ -54,6 +59,8 @@ export default { ...@@ -54,6 +59,8 @@ export default {
localStorage.setItem("tasks", JSON.stringify(this.tasks)); localStorage.setItem("tasks", JSON.stringify(this.tasks));
this.task = null; this.task = null;
this.$router.push("/"); this.$router.push("/");
this.$alertify.success('Add task successfully');
}, },
}, },
}; };
......
...@@ -32,6 +32,11 @@ ...@@ -32,6 +32,11 @@
</template> </template>
<script> <script>
import Vue from 'vue';
import VueAlertify from 'vue-alertify';
Vue.use(VueAlertify);
export default { export default {
created: function () { created: function () {
if (localStorage.getItem("tasks")) { if (localStorage.getItem("tasks")) {
...@@ -64,6 +69,7 @@ export default { ...@@ -64,6 +69,7 @@ export default {
localStorage.setItem("tasks", JSON.stringify(this.tasks)); localStorage.setItem("tasks", JSON.stringify(this.tasks));
this.task = null; this.task = null;
this.$router.push("/"); this.$router.push("/");
this.$alertify.warning('Edit task successfully');
}, },
}, },
}; };
......
Markdown is supported
0% or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment