當前位置: 首頁>>編程示例 >>用法及示例精選 >>正文


Vue.js app.directive()用法及代碼示例

如果同時傳遞名稱字符串和指令定義,則注冊全局自定義指令,如果僅傳遞名稱,則檢索已注冊的指令。

類型

interface App {
  directive(name: string): Directive | undefined
  directive(name: string, directive: Directive): this
}

示例

import { createApp } from 'vue'

const app = createApp({
  /* ... */
})

// register (object directive)
app.directive('my-directive', {
  /* custom directive hooks */
})

// register (function directive shorthand)
app.directive('my-directive', () => {
  /* ... */
})

// retrieve a registered directive
const myDirective = app.directive('my-directive')

相關用法


注:本文由純淨天空篩選整理自vuejs.org大神的英文原創作品 app.directive()。非經特殊聲明,原始代碼版權歸原作者所有,本譯文未經允許或授權,請勿轉載或複製。