【问题标题】:[Vue warn]: Property or method "v" is not defined on the instance but referenced during render[Vue 警告]:属性或方法“v”未在实例上定义,但在渲染期间被引用
【发布时间】:2017-11-14 16:02:38
【问题描述】:

这是我的组件。 el.focus() 插入时确实有效,但我在控制台上得到了[Vue warn]: Property or method "v" is not defined on the instance but referenced during render。 如何解除警告?

<script>
  export default {
    directives: {
      focus: {
        inserted (el) {
          el.focus()
        }
      }
    }
  }
</script>
<style lang="stylus" scoped>
  input
    width: 300px
    height: 30px
    border: 1px solid #000
</style>

<template lang="jade">
  div
    input(v-focus)
</template>

【问题讨论】:

    标签: javascript vue.js pug


    【解决方案1】:

    据我所知,当您将空属性传递给jade 时,它​​在纯HTML 中解释为attribute="attribute"。在您的情况下,实际的 HTML 是 v-focus="v-focus",vue 将其解释为使用不存在的属性 v 的表达式。

    您可以尝试input(v-focus="true"),因为传递给该指令的值并不重要。

    【讨论】:

    • 我在inserted 函数中打印binding 参数。然后我发现:当我的代码是input(v-focus),binding.expression 是v-focus。当我的代码是input(v-focus)时,绑定没有expression属性,警告消失
    猜你喜欢
    • 2020-07-25
    • 2021-08-13
    • 2021-02-10
    • 2017-04-08
    • 2019-02-20
    • 2021-11-27
    • 2019-10-23
    相关资源
    最近更新 更多