Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

ma-crud里面的 使用表单的字段组件插槽功能时,1怎么取详情信息?2值变化后方便提交吗? #158

Open
bingxinti opened this issue Apr 18, 2024 · 3 comments

Comments

@bingxinti
Copy link

例如 我在ma-crud里面使用了代码

<template #form-xxx>
这个时候,这里面我怎么读取到 详情的信息呢?(因为是ma-crud,所以新增和编辑时,有数据的详情信息)
大概意思是:怎么取值 {form} 或者 { record } ,我想读取到 record.xxx 显示,然后页面上改了这个值,最好保存时自动提交上去

    </template>
Copy link

dosubot bot commented Apr 18, 2024

嘿,@bingxinti!很高兴再次遇到你。👋 我正在查看你的问题,很快会给你一个完整的回答。请稍候哦!🚀

@bingxinti
Copy link
Author

现在的方案是
beforeOpenAdd Function()
beforeOpenEdit Function(record)

弹窗前进行处理的,能否支持
<template #form-xxx> 里面直接取值,变化后直接提交呢。

Copy link

dosubot bot commented Apr 18, 2024

To directly access and manipulate record.xxx within a <template #form-xxx> slot in ma-crud for both adding and editing scenarios, you can use Vue's reactive data handling and template syntax. Here's a streamlined approach:

  1. Initialize a reactive form data model in your component, using Vue 3's ref or reactive. This model will hold your form values.

  2. Bind this model to your form fields within the ma-crud component's slots. Use v-model for two-way binding of input fields to your reactive form data model.

Example:

<ma-crud>
  <template #form-xxx="{ record }">
    <input v-model="formData.xxx" />
  </template>
</ma-crud>

And in your component script:

import { ref } from 'vue';

export default {
  setup() {
    const formData = ref({
      xxx: '' // Initialize with default or loaded data
    });

    // Populate formData with `record` for edit scenarios
    function loadFormData(record) {
      formData.xxx = record.xxx;
    }

    return {
      formData,
      loadFormData
    };
  }
};

For editing, ensure formData.xxx is populated with record.xxx when the form is opened. This setup allows you to directly work with detail values within your form slots, facilitating both display and submission of changes without additional preprocessing steps.

Sources

About Dosu

This response is meant to be useful and save you time. It is not meant to be a precise solution, but rather a starting point for your own research.

Help me be more useful! Please leave a 👍 if this is helpful and 👎 if it is irrelevant.

If you want to continue the conversation, start your reply with @dosu-bot.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

1 participant