当我用axios.get调用数组时,如何调用它?我的表tr内部属性td没有出现,v-for语句是否无效?
<tr v-for="params in form" :key="params">
<td>{{params.title}}</td>
<td>{{params.company}}</td>
<td>{{params.company_url}}</td>
<td>{{params.location}}</td>
<td>{{params.description}}</td>
<td>{{params.date_posted}}</td>
</tr>
<script setup>
import axios from 'axios';
import { useRouter } from 'vue-router';
axios.get("API_URL/list",{
params: {
title: "",
company: "",
company_url: "",
location: "",
description: "",
date_posted: "",
}
})
.then((res)=>{
console.log(res.data)
return res.data
})axios.post数据在引入时使用参数是正确的。这张表格里寄来的数据?
const state = reactive({
form: {
title: "",
company: "",
company_url: "",
location: "",
description: "",
date_posted: ""
},
});
const formCreate = async () => {
const postdata = {
title: state.form.title,
company: state.form.company,
company_url: state.form.company_url,
location: state.form.location,
description: state.form.description,
date_posted: state.form.date_posted,
};发布于 2022-07-29 02:06:12
你好像错过了作业。不确定您的form是如何定义的,但是您可能希望使用ref或reactive并将数据分配给它。
尝试:
<tr v-for="params in form" :key="params">
<td>{{params.title}}</td>
<td>{{params.company}}</td>
<td>{{params.company_url}}</td>
<td>{{params.location}}</td>
<td>{{params.description}}</td>
<td>{{params.date_posted}}</td>
</tr>
<script setup>
import axios from "axios";
import { useRouter } from "vue-router";
import { ref } from "vue";
const form = ref([]); // <= define
axios
.get("API_URL/list", {
params: {
title: "",
company: "",
company_url: "",
location: "",
description: "",
date_posted: "",
},
})
.then((res) => {
console.log(res.data);
form.value = res.data; // <= assign
});
</script>https://stackoverflow.com/questions/73160888
复制相似问题