Покажи код
Это я писал в одном компоненте: <template> <el-form :model="ruleForm" :ref="ruleForm" label-width="120px" class="demo-ruleForm" style="width: 40%" align="left" > <el-form-item label="Автор" prop="author"> <el-input v-model="ruleForm.author_id"></el-input> </el-form-item> <el-form-item label="Название книги" prop="name_book"> <el-input v-model="ruleForm.name_book"></el-input> </el-form-item> <el-form-item label="Год издания"> <el-col :span="11"> <el-form-item prop="year_of_create"> <el-date-picker type="year" placeholder="Выберите год издания" v-model="ruleForm.year_of_create" style="width: 100%" /> </el-form-item> </el-col> </el-form-item> <el-form-item label="ISBN" prop="isbn"> <el-input v-model="ruleForm.isbn" /> </el-form-item> <el-form-item label="Цена" prop="price"> <el-input v-model="ruleForm.price" /> </el-form-item> <el-form-item label="Категория" prop="category"> <el-input v-model="ruleForm.category"></el-input> </el-form-item> <el-form-item label="Статус" prop="status_remove"> <el-input v-model="ruleForm.status_remove"></el-input> </el-form-item> <el-form-item label="№ акта" prop="num_of_act"> <el-input v-model="ruleForm.num_of_act"></el-input> </el-form-item> <el-form-item label="Дата списания" > <el-col :span="11"> <el-form-item prop="date_remove"> <el-date-picker type="date" placeholder="Выберите дату" format="yyyy/MM/dd" value-format="yyyy-MM-dd" v-model="ruleForm.date_remove" style="width: 100%;"></el-date-picker> </el-form-item> </el-col> </el-form-item> <el-form-item> <el-button type="primary" @click="editData(ruleForm)">Изменить</el-button> <el-button @click="resetForm('ruleForm')">Очистить</el-button> </el-form-item> </el-form> </template> <script> import axios from "axios"; export default { name: "editB", data: () => ({ ruleForm: { author_id: "", name_book: "", year_of_public: "", isbn: "", price: "", category: '', status_remove: '', num_of_act: '', date_remove: '' }, }), created() { this.getBookById(); }, methods: { async getBookById() { try { const response = await axios.get( `http://localhost:3000/books/${this.$route.params.id}` ); this.ruleForm.author_id = response.data.author_id; this.ruleForm.name_book = response.data.name_book; this.ruleForm.year_of_public = response.data.year_of_create; this.ruleForm.isbn = response.data.isbn; this.ruleForm.price = response.data.price; this.ruleForm.category = response.data.category; this.ruleForm.status_remove = response.data.status_remove, this.ruleForm.num_of_act = response.data.num_of_act, this.ruleform.date_remove = response.data.date_remove } catch (err) { console.log(err); } }, async editData() { this.ruleForm.year_of_public = (new Date(this.ruleForm.year_of_public)).getFullYear() await axios .put( `http://localhost:3000/books/${this.$route.params.id}`, this.ruleForm ) .then(() => this.$router.push("/books")) .catch((e) => console.log(e)); }, }, }; </script>
Ну так ты сам передаёшь айди, а не имя автора. this.ruleForm.author_id = response.data.author_id;
у меня таблица авторы привязана к данной таблицы, я хочу чтобы отображалось имя, а на бэк отправлялся/получал id
Обсуждают сегодня