# 选项/资源

# directives

  • 类型:Object

  • 详细:

    声明一组可用于组件实例中的指令。

  • 用法:

    const app = createApp({})
    
    app.component('focused-input', {
      directives: {
        focus: {
          mounted(el) {
            el.focus()
          }
        }
      },
      template: `<input v-focus>`
    })
    
    1
    2
    3
    4
    5
    6
    7
    8
    9
    10
    11
    12
  • 参考:自定义指令

# components

  • 类型:Object

  • 详细:

    声明一组可用于组件实例中的组件。

  • 用法:

    const Foo = {
      template: `<div>Foo</div>`
    }
    
    const app = createApp({
      components: {
        Foo
      },
      template: `<Foo />`
    })
    
    1
    2
    3
    4
    5
    6
    7
    8
    9
    10
  • 参考:组件基础