在选择视图VUE中未定义

gt0wga4j  于 2023-10-23  发布在  Vue.js
关注(0)|答案(1)|浏览(197)

当我尝试添加一个新项目时,我在选择视图中遇到了未定义的问题。你有什么想法我可以解决它,我试过V-如果,但我不为我工作。
我的代码看起来像这样:

<v-select
            v-model="project.kierownik_id"
            :items="formattedUsers"
            :item-props="itemProps"
            item-text="_id"
            item-value="_id"
            label="kierownik:"
            track-by="project.kierownik_id"
></v-select>

addProject() {
    console.log(' (before let paylod) Adding project:', this.project);
    let payload = { ...this.project, kierownik_id: this.project.kierownik_id, };
    axios
      .post('/project', payload)
      .then((res) => {
        console.log('Adding project:', this.project);
        this.$emit('hideEditProject', res.data);
      })
      .catch((err) => {
        this.error.message = err.response.data.message + ': ' + err.response.data.error;
        this.error.show = true;
      });
  },

data() {
  return {
    project: {
      kierownik_id: null,
    },
    dataCorrect: true,
    users: {},
    error: { show: false, message: '' },
    confirmDelete: false
  }
},

我想有选择查看没有未定义的文件时,我试图添加新的项目Picture

pnwntuvh

pnwntuvh1#

试试这个

<template>
  <div>
    <v-select
      v-if="project.kierownik_id !== null"
      v-model="project.kierownik_id"
      :items="formattedUsers"
      :item-props="itemProps"
      item-text="_id"
      item-value="_id"
      label="kierownik:"
      track-by="project.kierownik_id"
    ></v-select>
  </div>
</template>

<script>
import { ref, watch } from 'vue';

export default {
  setup() {
    const project = ref({
      // ...other project properties
      kierownik_id: null, // Set a default value, e.g., null
    });

    // Define your other data properties like formattedUsers, itemProps, etc.

    // Watch for changes to project.kierownik_id and handle them as needed
    watch(project.kierownik_id, (newValue, oldValue) => {
      // Handle the change, e.g., save it to the project object or perform other actions
    });

    return {
      project,
      // ...other data properties you want to expose to the template
    };
  },
};
</script>

相关问题