vscode中将console.log(this.ruleForm.price); var url = http://192.168.24.32:8080/javaWebMaven_war_exploded//addProduct.action?pid=${this.ruleForm.pid}&pname=${this.ruleForm.pname}&mprice=${this.ruleForm.price}&cname=${this.ruleForm.cname}; console.log(url); Axios.get(url).then(response1=>{ //后端添加成功 //跳转 console.log("商品添加成功!") // this.$router.push({path:'products/productMessage'}) }).catch(error=>{ console.log(error) })改成前端显示添加成功,用弹窗形式
时间: 2024-03-29 10:40:41 浏览: 204
如果想在前端页面上以弹窗形式显示添加成功,可以通过以下代码实现:
JavaScript:
```javascript
const message = '商品添加成功!';
alert(message);
```
这段代码中,我们使用 `alert` 方法弹出一个提示框,将添加成功的信息作为参数传递给它,从而实现以弹窗形式在前端页面上显示添加成功的信息。
同时,你也需要将原来的代码中的 `console.log("商品添加成功!")` 改成上述代码,以实现在前端页面上以弹窗形式显示添加成功的信息。
注意,这种方式只是将添加成功的信息以弹窗形式显示在了页面上,但并没有实现与后端的数据交互和真正的商品添加功能。如果需要实现商品添加功能,还需要调用后端接口并传递相应的参数。同时,需要将原来的请求方式从 `Axios.get` 改成 `Axios.post`,并且在请求中传递相应的参数以实现商品的添加。
相关问题
vscode中将console.log(this.ruleForm.price); var url = http://192.168.24.32:8080/javaWebMaven_war_exploded//addProduct.action?pid=${this.ruleForm.pid}&pname=${this.ruleForm.pname}&mprice=${this.ruleForm.price}&cname=${this.ruleForm.cname}; console.log(url); Axios.get(url).then(response1=>{ //后端添加成功 //跳转 console.log("商品添加成功!") // this.$router.push({path:'products/productMessage'}) }).catch(error=>{ console.log(error) })改成前端显示添加成功
如果想在前端页面上显示添加成功,可以通过以下代码实现:
HTML:
```html
<div id="result"></div>
```
JavaScript:
```javascript
const result = document.getElementById('result');
result.textContent = '商品添加成功!';
```
这段代码中,我们首先在 HTML 中添加一个 div 元素,它的 id 为 `result`,用于显示添加成功的信息。然后在 JavaScript 中,我们使用 `document.getElementById` 方法获取到该元素,再使用 `textContent` 属性将要显示的文本内容赋值给它,从而在前端页面上显示添加成功的信息。
同时,你也需要将原来的代码中的 `console.log("商品添加成功!")` 改成上述代码,以实现在前端页面上显示添加成功的信息。
注意,这种方式只是将添加成功的信息显示在了页面上,但并没有实现与后端的数据交互和真正的商品添加功能。如果需要实现商品添加功能,还需要调用后端接口并传递相应的参数。同时,需要将原来的请求方式从 `Axios.get` 改成 `Axios.post`,并且在请求中传递相应的参数以实现商品的添加。
vue.js中将http://localhost:8080/static这个字符串与变量a进行拼接
你可以使用字符串模板的方式进行拼接,例如:
```javascript
let a = 'filename.jpg';
let url = `http://localhost:8080/static/${a}`;
```
这样就可以将变量 `a` 插入到字符串中间,得到完整的 URL 字符串。