javascript - Vue Js仅间歇性地显示数据

标签 javascript vue.js

我想知道为什么 vue 有时只显示数据。我正确传递了 selectedclient,但 selectedclient.name 等仅间歇性显示。有谁知道发生了什么事吗?我使用 vue2 和 laravel 作为 api。这一切有时似乎有效,但有时却无效。我有点困惑...

<template>
  <div>
    <b-form @submit.prevent="editclient">
      <b-form-group
        label="Client Name"
        label-for="clientname"
      >
        <b-form-input
          v-model="clientname"
          id="clientname"
        ></b-form-input>
      </b-form-group>
      <b-form-group
        label="Client Email"
        label-for="clientemail"
      >
        <b-form-input
          type="email"
          v-model="clientemail"
          id="clientemail"
        ></b-form-input>
      </b-form-group>
      <b-form-group
        label="Client Phone"
        label-for="clientphone"
      >
        <b-form-input
          v-model="clientphone"
          id="clientphone"
        ></b-form-input>
      </b-form-group>
      <b-form-group
        label="Client Address"
        label-for="clientaddress"
      >
        <b-form-input
          v-model="clientaddress"
          id="clientaddress"
        ></b-form-input>
      </b-form-group>

      <b-button type="submit">Submit</b-button>
    </b-form>
  </div>
</template>
<script>
import axios from 'axios';
export default {
  name: 'EditClient',
  props: ['selectedclient'],
  data () {
    return {
      clientname: this.selectedclient.name,
      clientemail: this.selectedclient.email,
      clientphone: this.selectedclient.phone,
      clientaddress: this.selectedclient.address
    }
  },
  methods: {
    editclient: async function () {
      var id = this.selectedclient.id;
      var name = this.clientname;
      var email = this.clientemail;
      var phone = this.clientphone;
      var address = this.clientaddress;

      var client = new Array(id, name, email, phone, address);

      axios.post('http://localhost/ficticious/fApi/clientEdit', client)
        .then(function (response) {
          console.log(response);
        })
        .catch(function (error) {
          console.log(error);
        })
    }
  }
}
</script>

最佳答案

这些更多的是提示而不是解决方案:您不需要在数据中重新分配 Prop 。某些东西应该是 Prop 或数据。您可以将 v-model 放在数据上,但不能放在 prop 上,因为 props 是不可修改的。 (你可以看看 .sync 吗?)

要弄清楚发生了什么,你安装了 vue devtools 吗?

关于javascript - Vue Js仅间歇性地显示数据,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/70109497/

相关文章:

javascript - Vue.js 模板连接 Prop

javascript - Vue - 是否可以动态设置 html 元素的样式?

javascript - 使用 Google API 检索联系人姓名

javascript - 在 window.onload 之前运行 javascript 需要很长时间

javascript - jQuery - 元素检测性能

javascript - 有没有办法在其 Action 或突变中获取 nameSpaced vuex 模块的名称?

css - VueJS Bootstrap CSS 如何在页面底部放置元素?

javascript - 从组件内更改 vue 实例变量

javascript - 使 map 响应

javascript - HTML 元素会有加载成功的 promise 吗?