【发布时间】:2021-01-08 06:14:37
【问题描述】:
我似乎不知道如何进行 POST 或连接到后端 (Laravel 8)。我正在研究 Quasar 和 Laravel。 我有两个单独的文件夹,一个在后端,一个在前端。
我分别运行它们(左:Laravel,右:Quasar)
我已经在 quasar 代理中创建了 devServer 来获取后端。
devServer: {
https: false,
port: 8080,
open: true,
proxy: {
// proxy all requests starting with /api to jsonplaceholder
"/api": {
target: "http://localhost:8080/", //tried this one also http://127.0.0.1:8000
changeOrigin: true,
pathRewrite: {
"^/api": ""
}
}
}}
这是我的 Vue 文件。
<!-- Dialog -->
<q-dialog
v-model="addProductForm"
transition-show="slide-up"
transition-hide="slide-down"
>
<q-card style="width: 700px; max-width: 80vw;">
<q-card-section>
<div class="text-h6">Add Category</div>
</q-card-section>
<div class="q-pa-md">
<q-input outlined v-model="categoryName" label="Category name" />
<div class="q-ma-md float-right">
<q-btn label="Cancel" />
<q-btn
class="q-ml-md "
label="Create"
color="primary"
@click="createCategory"
/>
</div>
</div>
</q-card>
</q-dialog>
<!-- Dialog (END) -->
</q-card></q-page>
<script>
import axios from "axios";
export default {
data() {
return {
addProductForm: true,
categoryName: "Shoes",
categories: []
};
},
methods: {
createCategory() {
this.$axios
.post("http://127.0.0.1:8000/api/createCategory", this.categoryName)
.then(response => {
// this.categories.unshift(response.data);
console.log(response.data);
})
.catch(() => {
this.$q.notify({
color: "negative",
position: "top",
message: "Unable to save category name",
icon: "report_problem"
});
});
}
}
// mounted() {
// console.log(this.categories);
// }
};
</script>
每次我发帖。它总是说 categoryName 是空的。
这是我的 api.php
我的类别控制器。
谁能知道如何进行这项工作?它确实说 categoryName 是空的。
【问题讨论】:
-
把这个
.post("http://127.0.0.1:8000/api/createCategory", this.categoryName)改成.post("http://127.0.0.1:8000/api/createCategory", { categoryName: this.categoryName})
标签: laravel vue.js quasar-framework