我对Vue很陌生,我所做的非常简单,我认为一定是一些反应性问题,问题是我正在做一个axios.get(),当我控制台.log(res.data)时,它显示一切正常。
但当我试图使res.data=反应对象时,它只记录这个Proxy{}(就像里面什么都没有一样),我会留下代码和2张图片,每个场景一次。
console.log res.data正常时的代码:
<script>
import { onMounted, reactive, ref } from 'vue';
import axios from 'axios';
export default {
name: 'HomeView',
setup() {
const state = reactive({
destinations: []
})
const destinations = ref([]);
onMounted( () => {
axios.get('https://my-json-server.typicode.com/Tommydemian/vue-school-router/db')
.then(response => response.data.destinations)
.then( data => console.log(data) )
})
return {
state
}
}
}
</script>
以下是回应:
以下是console.log中代码和图像的更改:
const state = reactive({
destinations: []
})
onMounted( () => {
axios.get('https://my-json-server.typicode.com/Tommydemian/vue-school-router/db')
.then(response => response.data.destinations)
.then( data => (state.destinations = data) )
})
console.log(state.destinations)
img: