7
2

Delete article

Deleted articles cannot be recovered.

Draft of this article would be also deleted.

Are you sure you want to delete this article?

More than 5 years have passed since last update.

Vue.jsでカスタムディレクティブ作って正しく名前指定してるのに、[Vue warn]: Failed to resolve directiveになるとき

Posted at

前提

Vue.js 2.5.13

結論

大文字のディレクティブ名作っても小文字で評価されるらしい。

サンプル

js

main.js
var app = new Vue({
    el: '#app',
    directives: {
        focusLocal: {
            inserted: function(el) {
                el.focus()
            }
        }
    }

html

index.html
<input v-focusLocal>

エラー内容 (jsconsole)

vue.js:584 [Vue warn]: Failed to resolve directive: focuslocal

(found in <Anonymous>)

エラーメッセージの時点で小文字化されてる。

参考

基礎から学ぶ Vue.js

カスタムディレクティブ — Vue.js

コンポーネントの登録 — Vue.js

https://jp.vuejs.org/v2/guide/components-registration.html#%E3%82%B3%E3%83%B3%E3%83%9D%E3%83%BC%E3%83%8D%E3%83%B3%E3%83%88%E5%90%8D
ディレクティブ名じゃなくて、コンポーネント名ですが、全て小文字のケバブケース推奨ってことらしい。

7
2
0

Register as a new user and use Qiita more conveniently

  1. You get articles that match your needs
  2. You can efficiently read back useful information
  3. You can use dark theme
What you can do with signing up
7
2

Delete article

Deleted articles cannot be recovered.

Draft of this article would be also deleted.

Are you sure you want to delete this article?