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


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

用於向 vnode 添加自定義指令。

類型

function withDirectives(
  vnode: VNode,
  directives: DirectiveArguments
): VNode

// [Directive, value, argument, modifiers]
type DirectiveArguments = Array<
  | [Directive]
  | [Directive, any]
  | [Directive, any, string]
  | [Directive, any, string, DirectiveModifiers]
>

細節

使用自定義指令包裝現有 vnode。第二個參數是一個自定義指令數組。每個自定義指令也表示為 [Directive, value, argument, modifiers] 形式的數組。如果不需要,可以省略數組的尾元素。

示例

import { h, withDirectives } from 'vue'

// a custom directive
const pin = {
  mounted() {
    /* ... */
  },
  updated() {
    /* ... */
  }
}

// <div v-pin:top.animate="200"></div>
const vnode = withDirectives(h('div'), [
  [pin, 200, 'top', { animate: true }]
])

相關用法


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