내 개체에서 값을 가져 오려고하면 이상한 경고가 표시됩니다. 얻는 가치는 JSON입니다. 여기서 문제가 무엇인지, 내 코드가 무엇이 문제인지 궁금합니다. 내 변수에 정의되지 않은 이유는 무엇입니까?변수가 서버에서 가져 오는 동안 정의되지 않았습니다.
내 템플릿 코드 : 좀 더 자세한 정보가 필요하면
<template>
<textarea id="terms" v-model="terms.value" name="terms" type="text" rows="20"></textarea>
<button class="btn waves-effect waves-light " v-on:click="updateUserProfile">Update Profile</button>
</template>
<script>
import firebase from 'firebase'
import axios from 'axios'
export default {
data: function() {
return {
id: '',
email: '',
terms: {},
}
},
methods: {
getUserProfile: function() {
var accessToken;
var self = this;
var config = {
headers: {'Authorization': 'Bearer ' + accessToken}
};
axios.get('https://api-link/', config).
then(response => {
console.log("Response on GET OK: " + response)
self.id = response.data.id
self.terms = response.data.terms
})
.catch(e => {
console.log("Error on GET: " + e)
});
}).catch(function(error) {
console.log("Error on getting token: " + error)
});
},
updateUserProfile: function() {
var accessToken;
var self = this;
var config = {
headers: {'Authorization': 'Bearer ' + accessToken}
};
axios.put('https://api-link/',
{
terms: self.terms
}, config).
then(response => {
console.log("Response on PUT: " + response)
self.email = response.data.email
self.id = response.data.id
self.userType = response.data.user_type
self.terms = response.data.terms
})
.catch(e => {
console.log("Error on PUT: " + e)
});
},
},
mounted() {
this.getUserProfile()
},
}
</script>
아래는 내 콘솔에서 내 스크린 샷입니다, pls는 주석 처리합니다. 도움을 주셔서 감사합니다. 몇 시간 동안 여기에 붙어 있습니다. 또한 당신이 당신의 변수에 응답 데이터를 할당 할 수 있습니다 다음하지 않을 경우 응답 먼저 정의에있다
어떤 코드 줄이 문제입니까? – Mikkel
내 getUserProfile()에 용어 값 얻기 – Muli
한 가지 문제는 템플릿에 두 개의 루트 요소가 있다는 것입니다. 'div '와 같은 태그에'textarea'와'button'을 포함시켜야합니다. – Bert