我是编程新手,我有一个与后端对话的网站(用 GO 编写)。我必须将我的 javascript 中的 url 设置为可配置的。老实说,我真的不知道该怎么做。我以前从未听说过使 url 可配置。
那是什么以及如何使 url 可配置?我还将插入一些代码。我使用 javascript,vuejs
<script>
/* eslint-disable */
export default {
name: 'listCakes',
data() {
return {
cakes: [],
errors: [],
currentPage: 1,
alerts: [],
total_cakes: 1,
cake_fields: ['id', 'purpose']
}
},
created() {
this.loadCakes(0, 10)
},
watch: {
currentPage: function (newPage) {
this.loadCakes(newPage, 10)
}
},
methods: {
newCake(evt) {
evt.preventDefault();
window.API.post('https://192.168.78.92:8000/api/v1/cake', '{}')
.then((response) => {
console.log(response.data);
this.loadCake(response.data.id)
})
.catch((error) => {
console.log(JSON.stringify(error))
})
},
editCake(record, index) {
var id = record.id
this.$router.push({ name: 'editCake', params: { id } })
},
loadCake(id) {
this.$router.push({ name: 'editCake', params: { id } })
},
loadCakes(currentPage, limit) {
if (!(Number.isInteger(currentPage) && Number.isInteger(limit))) {
currentPage = 0
limit = 10
}
var offset = (currentPage - 1) * limit
window.API.get('cake?offset=' + offset + '&limit=' + limit)
.then(response => {
this.cakes = response.data.cakes;
this.total_cakes = response.data.total;
console.log(response.data.cakes)
})
.catch(e => {
this.errors.push(e)
})
}
}
}