javascript - 使用 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>
解决方案
推荐阅读
- git - 无法将提交两次推送到我的遥控器
- javascript - 为什么我在从 config/custom.js 导入变量时阻止了跨域请求
- angular - Angular:如何将指令微语法与 cdkConnectedOverly 一起使用?
- google-cloud-build - Google Cloud Build 中容器之间的网络连接
- java - Finatra TooLongMessageException HTTP 内容长度超过 5242880 字节,尽管标志设置了更多字节
- powershell - 带有列表的 Powershell 继承
- javascript - if(a) & if(a!=null && a!=undefined) 的区别
- asp.net - 在 asp.net 中打印 DataGridView 的问题
- android - Android Studio 默认 Junit Runner
- c# - 使用变量键将文本框绑定到字典