V-Select和数据的问题

发布于 2025-01-28 13:52:25 字数 1153 浏览 1 评论 0原文

下午好朋友,然后我要告诉你我的错误。我正在为用户屏幕工作,您可以在其中进行注册和编辑。输入注册部分时,您不必在数据库中显示您已经扮演的角色。但是在编辑屏幕上,它已经分配了一个角色,因此我必须将其带入它(就像文本场一样),但我无法将其加载。 屏幕的附加图像:

进入屏幕后立即进行调试器时,我意识到它正在返回作为数组的角色。它很好地向我展示了角色,但它并没有将其放在选择中。 图像下方的错误图像是我使用的代码。

 <v-select
            label="Rol"
            v-model="form.rolId"
            :items="roles"
            item-value="value"
            item-text="text"
            :rules="[(v) => !!v || 'Este campo es requiredo']"
            required
          >
          </v-select>

 data() {
return {
  form: {},
  roles: [
    { value: "Agente", text: "Agente" },
    { value: "Administrador", text: "Administrador" },
  ],
};

},

Good afternoon friends, then I'm going to tell you my mistake. I am working for a users screen, where you have your registration and editing. When you enter the register section you don't have to show the role you already have in the database. But on the edit screen, it already has a role assigned, so I would have to bring it to it (as it does with the text-fields) But I can't get it to load them.
attached images of the screen:
enter image description here
enter image description here

When I do a debugger as soon as I enter the screen, I realize that it is returning the roles as an array. And it shows me the role well, but it doesn't place it in the select.
Attached image of the error, below the images is the code that I use.
enter image description here

 <v-select
            label="Rol"
            v-model="form.rolId"
            :items="roles"
            item-value="value"
            item-text="text"
            :rules="[(v) => !!v || 'Este campo es requiredo']"
            required
          >
          </v-select>

 data() {
return {
  form: {},
  roles: [
    { value: "Agente", text: "Agente" },
    { value: "Administrador", text: "Administrador" },
  ],
};

},

如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。

扫码二维码加入Web技术交流群

发布评论

需要 登录 才能够评论, 你可以免费 注册 一个本站的账号。

评论(1

尬尬 2025-02-04 13:52:25

您必须在V-Model上放置一个默认值,以使其在选择中加载数据。

请参阅此处的Codepen

You have to put a default value on your v-model for it to load the data in the select.

see codepen here

~没有更多了~
我们使用 Cookies 和其他技术来定制您的体验包括您的登录状态等。通过阅读我们的 隐私政策 了解更多相关信息。 单击 接受 或继续使用网站,即表示您同意使用 Cookies 和您的相关数据。
原文