Vue App API表单可在localhost上运行,但无法一次部署

时间:2020-08-03 02:34:50

标签: javascript php mysql vue.js axios

我的代码在本地服务器上运行良好,但是一旦部署到网站上,就无法显示数据。我不断收到“由于未连接表单而取消了表单提交”。 Axios实际上是将数据放入我的数据库中,只是它不会显示在我的界面上。当我console.log(app.Users)时,它返回未定义。谢谢

<script>
      var app = new Vue({
        el: "#app",
        data: {
          errorMsg: "",
          successMsg: "",
          showAddModal: false,
          showEditModal: false,
          showDeleteModal: false,
          users: [],
          newUser: { name: "", email: "", phone: "" },
          currentUser: {},
        },
        mounted: function () {
          this.getAllUsers();
        },
        methods: {
          getAllUsers() {
            axios
              .get(
                "http://jakewoodruff.com/Projects/crud-vue-php/process.php?action=read"
              )
              .then(function (response) {
                if (response.data.error) {
                  app.errorMsg = response.data.message;
                } else {
                  app.users = response.data.users;
                  console.log(app.users);
                }
              });
          },
          addUser() {
            var formData = app.toFormData(app.newUser);
            axios
              .post(
                "http://jakewoodruff.com/Projects/crud-vue-php/process.php?action=create",
                formData
              )
              .then(function (response) {
                app.newUser = { name: "", email: "", phone: "" };
                if (response.data.error) {
                  app.errorMsg = response.data.message;
                } else {
                  app.successMsg = response.data.message;
                  app.getAllUsers();
                }
              });
          }

0 个答案:

没有答案