zoukankan      html  css  js  c++  java
  • vue组件传值 非 Prop 的 Attribute

    vue组件传值 非 Prop 的 Attribute

    一个非 prop 的 attribute 是指传向一个组件,但是该组件并没有相应 prop 定义的 attribute。

    因为显式定义的 prop 适用于向一个子组件传入信息,然而组件库的作者并不总能预见组件会被用于怎样的场景。这也是为什么组件可以接受任意的 attribute,而这些 attribute 会被添加到这个组件的根元素上。

    例如,想象一下你通过一个 Bootstrap 插件使用了一个第三方的 bootstrap-date-input 组件,这个插件需要在其 input 上用到一个 data-date-picker attribute。我们可以将这个 attribute 添加到你的组件实例上:

    <bootstrap-date-input data-date-picker="activated"></bootstrap-date-input>
    

    然后这个 data-date-picker="activated" attribute 就会自动添加到 的根元素上。

    禁用 Attribute 继承

    如果你不希望组件的根元素继承 attribute,你可以在组件的选项中设置 inheritAttrs: false。例如:

    Vue.component('my-component', {
      inheritAttrs: false,
      props: ["label", "value"],
    })
    

    在my-component组件上,除了label和value外,其他父组件的属性不会传递到子组件上。

  • 相关阅读:
    判断整数是否为质数?
    汇编debug
    DOS命令 Net config server Net config workstation
    DecimalField的使用
    BiNGO的GO分析
    GO富集分析 信号通路
    Cytoscape软件简介
    git pull遇到错误:error: Your local changes to the following files would be overwritten by merge:
    note3
    基因id
  • 原文地址:https://www.cnblogs.com/mengfangui/p/12272205.html
Copyright © 2011-2022 走看看