简体   繁体   English

如何在尚未评估的情况下将变量传递给自定义组件?

[英]How do I pass a variable through to a custom component without having it evaluated yet?

I have a custom component:我有一个自定义组件:

<template>
  <div class="form-group">
    <label for="desc">{{label}}</label>
    <input id="desc" type="text" class="form-control input-sm"
           :name="label"
           :readonly="readonly"
           v-bind:value="value"
           v-on:input="$emit('input', $event.target.value)"
           v-validate="validate"
    />
    <div class="error-feedback">{{ errors.first(label) }}</div>
    {{readonly}}<!-- debugging -->
  </div>
</template>

<script>
export default {
  name: 'FormGroup',
  props: {
    label: String,
    value: String,
    readonly: String,
    validate: String
  },
  data: function() {
    return {
    }
  }
}
</script>

<style scoped>
  .error-feedback {
    color: #cc3333;
  }
</style>

When I call it with:当我调用它时:

  <FormGroup label="Channel" readonly="device_config.enabled" validate="required" v-model="device_config.some_setting" />

The custom component receives the 'readonly' property as the literal string "device_config.some_setting" rather than the value contained in device_config.some_setting .自定义组件接收 'readonly' 属性作为文字字符串"device_config.some_setting"而不是包含在device_config.some_setting的值。

How can I get my custom component to make field readonly dependent on a value in the calling component's model which is passed-in?如何让我的自定义组件使字段只读依赖于传入的调用组件模型中的值?

使用v-bind:readonly="setting"并且setting应该是在你的父组件中定义的一个属性:

    <FormGroup label="Channel" :readonly="setting" validate="required" v-model="device_config.some_setting" />

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

相关问题 如何在不调用方法的情况下通过另一个方法传递方法,并将变量 object 传递给它? - How do I pass a method through another method without it being called, and pass a variable object into it? 如何将参数传递给包含在变量/对象中但尚未求值的javascript函数? - How to pass arguments to a javascript function that is contained in a variable/object and has yet to be evaluated? 如何通过超链接传递变量? - How do I pass a variable through a hyperlink? 如何在父项更改时将道具传递给反应组件但不更新子项中的该道具? - How do I pass a prop to a react component yet not update that prop in the child when parent changes? 如何通过 Angular 自定义组件传递 class - How to pass class through an Angular Custom component 在React类中:如何在同一组件内传递变量 - In a react class: How do I pass a variable inside same component 如何在 React 中将 const 变量作为道具传递给组件? - How do I pass a const variable to a component as a prop in React? 如何将变量从一个组件传递到另一个组件? - How do I pass a variable from one component to another? 如何通过网址传递JavaScript变量? - How do I pass a javascript variable through a URL? 如何通过反应中的组件传递变量的值? - How do I pass the value of a variable through the components in react?
 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM