vue webpack自定義指令全域性匯入方法

2021-10-04 11:09:31 字數 589 閱讀 9394

首先在src目錄下建立乙個指令模組資料夾,裡面有乙個index.js

src/directives/index.js

// index.js

module.exports =

, componentupdated:

function

(el, binding, vm)},

seconddir:

, componentupdated:

function

(el, binding, vm)

}}

然後在main.js裡進行引入和全域性呼叫

// main.js裡全域性指令匯入

import

*as directives from

'@/directives/'

object.

keys

(directives)

.foreach

(key => vue.

directive

(key, directives[key]

))

關於更多指令官網教程

自定義指令

像v if,v show等,是vue已經內建的指令,我們也可以使用directive來自定義指令 其中的blue要被引號所包裹,不然會被識別為變數來進行查詢全域性自定義指令 vue.directive focus vue.directive color var vm new vue 簡寫形式,代表我...

自定義指令

自定義指令有兩種方法 complieprovider.directive 指令名 function return restrict acem replace true,transclude true,template content return restrict acem replace true...

自定義指令

directives.js 存放 自定義標籤 strict require scope link 接收兩個引數 第乙個引數表示自定義指令的名稱 在頁面中使用 分隔單詞,在自定義指令中通過駝峰式命名 第二個引數表示自定義指令處理函式 返回值是乙個物件,用來描述我們自定義指令的 描述自定義指令的物件有一...