Spring boot Im在单独的服务文件中与axios混淆
现在我正在学习vue.js,我想从我的后端使用API(使用spring) 这是我的服务.jsSpring boot Im在单独的服务文件中与axios混淆,spring-boot,vue.js,Spring Boot,Vue.js,现在我正在学习vue.js,我想从我的后端使用API(使用spring) 这是我的服务.js import axios from "axios"; class LowonganKerjaService { retrieveAllLoker() { return axios.get('http://localhost:8081/api/listLoker'); } deleteLoker(idLowongan){ return axios
import axios from "axios";
class LowonganKerjaService {
retrieveAllLoker() {
return axios.get('http://localhost:8081/api/listLoker');
}
deleteLoker(idLowongan){
return axios.delete('http://localhost:8081/api/${idLowongan}');
}
}
export default new LowonganKerjaService();
这是我的组件
<template>
<div class="container">
<h3>All Courses</h3>
<div v-if="message" class="alert alert-success">
{{message}}
</div>
<div class="container">
<table class="table">
<thead>
<tr>
<th>Id</th>
<th>Description</th>
</tr>
</thead>
<tbody>
<tr v-for="loker in loker" v-bind:key="loker.idLowongan">
<td>{{loker.idLowongan}}</td>
<td>{{loker.deskripsi}}</td>
<td>
<button class="btn btn-warning" v-on:click="deleteLokerClicked(loker.idLowongan)">
Hapus
</button>
</td>
</tr>
</tbody>
</table>
</div>
</div>
</template>
<script>
import LowonganKerjaService from '../../service/LowonganKerjaService';
export default {
name : "LokerList",
data() {
return{
loker : []
};
},
methods:{
refreshLoker(){
LowonganKerjaService.retrieveAllLoker()
.then(response => {
this.loker = response.data;
});
},
deleteLokerClicked(idLowongan){
LowonganKerjaService.deleteLoker(idLowongan).then(()=> {
this.message = 'Loker dengan ${idLowongan} berhasil dihapus';
this.refreshLoker();
});
}
},
created(){
this.refreshLoker();
}
};
</script>
<style>
</style>
所有课程
{{message}}
身份证件
描述
{{loker.idLowongan}}
{{loker.deskripsi}}
哈布斯
从“../service/LowonganKerjaService”导入LowonganKerjaService;
导出默认值{
名称:“洛克列表”,
数据(){
返回{
洛克:[]
};
},
方法:{
refreshLoker(){
LowonganKerjaService.retrieveAllLoker()
。然后(响应=>{
this.loker=response.data;
});
},
deleteLokerClicked(idLowongan){
LowonganKerjaService.deleteLoker(idLowongan)。然后(()=>{
this.message='Loker dengan${idLowongan}berhasil dihapus';
这个。refreshLoker();
});
}
},
创建(){
这个。refreshLoker();
}
};
我犯了这个错误
未能编译
./src/service/LowonganKerjaService.js模块错误(来自
./node_modules/eslint loader/index.js):
D:\Kuliah\TERM
6\Propensi\Implementasi\frontend sixacti\src\service\LowonganKerjaService.js
10:17已定义错误“idLowongan”,但从未使用过没有未使用的变量
✖ 1个问题(1个错误,0个警告)
哦,当我在这些服务中使用${}时,我也遇到了错误。
为什么那个错误声明从未使用过我的“idLowongan”?是因为我弄错了我的Syntak还是什么
请有人帮我解释一下原因
谢谢
**很抱歉我的语言不好从代码的外观来看,当您尝试使用JS模板文字时,您似乎使用了单引号('),而不是反勾(`)。你可以看到一个例子。因为在您的示例中它是一个字符串,而不是一个模板文本,所以函数参数中的变量永远不会被使用 尝试将服务的删除方法中的代码更改为:
return axios.delete(`http://localhost:8081/api/${idLowongan}`)