methods: { onSubmit() { this.$message('添加成功!') }, onCancel() { this.$message({ message: '取消!', type: 'warning' }) }, //实现添加 addStudent(){ //后端更新 var url = ` http://localhost:8080/javaWebMaven_war_exploded/addStudent.action?stuno=${this.form.stuno}&stuname=${this.form.stuname}&stuage=${this.form.stuage}`; Axios.get(url).then(response=>{ //前端更新 this.$set(this.tableData, this.index, this.form); }).catch(error=>{ console.log("添加失败了:"+error) }) } }补全代码
时间: 2024-02-14 11:19:03 浏览: 78
根据你提供的代码,可能需要对其进行以下修改:
1. `Axios` 库需要引入:
在 Vue 组件的 `script` 标签中,需要引入 `axios` 库,例如:
```
import axios from 'axios';
```
2. `this.index` 变量未定义:
根据你提供的代码,`this.index` 变量未定义,可能需要在组件的 `data` 中定义它,例如:
```
data() {
return {
form: {
stuno: '',
stuname: '',
stuage: '',
},
tableData: [],
index: null,
};
},
```
3. 代码实现:
根据上述修改,补全代码如下:
```
methods: {
onSubmit() {
this.$message('添加成功!');
},
onCancel() {
this.$message({
message: '取消!',
type: 'warning',
});
},
addStudent() {
// 后端更新
const url = `http://localhost:8080/javaWebMaven_war_exploded/addStudent.action?stuno=${this.form.stuno}&stuname=${this.form.stuname}&stuage=${this.form.stuage}`;
axios.get(url)
.then(response => {
// 前端更新
this.$set(this.tableData, this.index, this.form);
})
.catch(error => {
console.log("添加失败了:" + error);
});
},
},
```
阅读全文
相关推荐
![docx](https://img-home.csdnimg.cn/images/20241231044901.png)
![docx](https://img-home.csdnimg.cn/images/20241231044901.png)
![zip](https://img-home.csdnimg.cn/images/20241231045053.png)
![](https://csdnimg.cn/download_wenku/file_type_ask_c1.png)
![](https://csdnimg.cn/download_wenku/file_type_ask_c1.png)
![](https://csdnimg.cn/download_wenku/file_type_ask_c1.png)
![](https://csdnimg.cn/download_wenku/file_type_ask_c1.png)
![](https://csdnimg.cn/download_wenku/file_type_ask_c1.png)
![](https://csdnimg.cn/download_wenku/file_type_ask_c1.png)
![](https://csdnimg.cn/download_wenku/file_type_ask_c1.png)
![](https://csdnimg.cn/download_wenku/file_type_ask_c1.png)
![](https://csdnimg.cn/download_wenku/file_type_ask_c1.png)
![](https://csdnimg.cn/download_wenku/file_type_ask_c1.png)
![](https://csdnimg.cn/download_wenku/file_type_ask_c1.png)
![](https://csdnimg.cn/download_wenku/file_type_ask_c1.png)
![](https://csdnimg.cn/download_wenku/file_type_ask_c1.png)
![](https://csdnimg.cn/download_wenku/file_type_ask_c1.png)
![](https://csdnimg.cn/download_wenku/file_type_ask_c1.png)
![](https://csdnimg.cn/download_wenku/file_type_ask_c1.png)
![](https://csdnimg.cn/download_wenku/file_type_ask_c1.png)