【发布时间】:2021-02-05 13:09:09
【问题描述】:
我正在使用 vue.js 和 php 进行 CRUD。我安装了 axios,我相信它正在工作。就是不知道怎么调用连接数据库的php文件并创建、读取...
文件夹结构:
我的脚本摘录:
<script>
import axios from 'axios';
export default {
name: "HelloWorld",
data() {
return{
showAddModal: false,
showEditModal: false,
showDeleteModal: false,
errorMsg: "",
successMsg: "",
projects: [],
newProject: {
title: "",
},
currentProject: {},
}
},
created: function () {
this.getAllProjects();
},
methods: {
getAllProjects: function () {
axios
.get("../php/action.php?action=read")
.then(function (response) {
if (response.data.error) {
this.errorMsg = response.data.message;
} else {
this.projects = response.data.projects;
}
});
},
【问题讨论】:
-
您需要运行某种 PHP 服务器才能调用它。您当前运行 PHP 文件的设置是什么?
-
是真的,有这个细节。我该如何解决这个问题? xampp 会起作用吗?
-
“通话”是什么意思?为什么不使用 AJAX 请求?