【问题标题】:Create Vue Directive that doesn't expect an expression创建不需要表达式的 Vue 指令
【发布时间】:2017-11-29 06:01:48
【问题描述】:

这段代码:

// template in pug
#review-step.container

    .panel(v-test.a)

// in main.js
Vue.directive('test', function(el, binding) {
    console.log(binding.modifiers)
})

给出这些错误:

[Vue warn]: Property or method "v" is not defined on the instance but referenced during render. ...
[Vue warn]: Property or method "test" is not defined on the instance but referenced during render. ...
TypeError: Cannot read property 'a' of undefined. ...

如果我将指令更改为v-test.a="",那么它可以正常工作。同样,v-prev-cloakv-once 都可以正常工作,因此不会错误地编译模板。

我想知道如何创建一个不需要表达式的指令,例如来自bootstrap-vuev-prev-cloakv-b-modal(顺便说一句,这就是我真正在这里的原因,因为指令也有同样的问题)。

我在任何地方都找不到这个,vue custom directives 文档一无所有,并且在 vue 存储库中搜索 directive pre 或类似内容并没有帮助我了解 vue 团队是如何实现这一点的。

【问题讨论】:

    标签: vue.js pug


    【解决方案1】:

    原来是哈巴狗。我不知道 vue 团队是如何让他们的指令正常工作的,但 pug 是mirroring attributes

    不幸的是,我需要弄清楚如何将 doctype 选项传递给 vue webpack 加载器,除非我想在每个模板的顶部声明它。

    【讨论】:

      猜你喜欢
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 2022-07-22
      • 1970-01-01
      • 1970-01-01
      相关资源
      最近更新 更多