vue.js - Axios and vue-resource put method doesn't work -
i have on front vuejs , on backend java. in 1 component bring users database.
users.vue
getusers() { this.$http.get("/user") .then((response) => { this.users = response.data.users; }) }
still here use v-for bring users in component user.vue.
<app-user v-for="user in users" :user="user" :key="user.index"></app-user>
in user component have router link takes me page can edit username.
user.vue
<p class="user-name">{{user.firstname}}</p> <router-link :to="'/users/edit-user/'+user.id"> <a ><i class="ti-pencil-alt" aria-hidden="true"></i></a> </router-link>
edituser.vue
<template> <input type="text" :value="user.firstname" v-model="userinfo.firstname"> </template> <script> export default { data() { return { user: {}, userinfo: { firstname: '', } } }, created() { this.getusers(); }, methods: { getusers() { this.$http.get("/user/" + this.$route.params.id) .then((response) => { this.user = response.data; }) }, updateuser() { axios.put('/user', this.userinfo, {'headers':{'x-auth-token':localstorage.token}}, {'headers':{'content-type': 'application/json'}}) .then((response) => { console.log("success! edited user"); }) .catch((response) => { console.log('error in edit'); }) } }, } </script>
i started learning vuejs month ago , still have learn :).
in input use :value="user.firstname"
bring value firstname exists. try use v-model="userinfo.firstname"
new value username, when put this, value, existed already, disappears input.
to save data post works fine axios. don't know why post doesn't work vue-resource. tried put axios too, edit when press save button, on edituser.vue, request doesn't go server.
i because saw in backend don't error, nothing, if use post or can or save users.
what do wrong in code don't edit user?
please check postman or arc if answer dabase. try put userinfo in postaman body , see back.
if have more username send database , don't fill inputs(that required) normal error , of course values not edited.
i think don't see error because somehow app doesn't response errors server.
if in postman or arc can edit put means problem code.
Comments
Post a Comment