首页 > 解决方案 > 使用 if 使价值动态化 - Vue

问题描述

在我的子组件(Form.vue)中正在使用不同的父组件(A modal.vue 和 General.vue)。在 Modal.vue 我没有访问权限,information因为我不需要它。在 General.vue 中,我使用可通过 props 使用的对象信息。

我的问题:我可以这样做吗?我现在使用具有几乎相同代码的模板来确保在 Modal.vue 中表单仍然可以工作,因为如果我不使用 v-if,它会出现错误。

执行以下代码:

<template>
    <div>
        <div class="form-group row" v-for="field in JSON.parse(processingData.fields)" :key="field.label">
            <div class="col-12">
                <div v-if="field.type == 'text'" :class="'col-' + field.cols">
                    <label>{{ field.label }}</label>

                    <template v-if="information">
                        <input
                            class="form-control form-control-lg form-control-solid"
                            type="text"
                            :ref="field.field"
                            @input="getS(field.field, $event.target.value)"
                            v-model="information[field.field]"
                            value=""
                        />
                    </template>

                    <template v-if="!information">
                        <input
                            class="form-control form-control-lg form-control-solid"
                            type="text"
                            :ref="field.field"
                            @input="getS(field.field, $event.target.value)"
                        />
                    </template>
                </div>
           </div>
      </div>
 </div>
</template>

标签: javascriptvuejs2

解决方案


推荐阅读