2017-06-13 257 views
1

这是我的组件。 el.focus()确实在插入时有效,但我在控制台上得到了[Vue warn]: Property or method "v" is not defined on the instance but referenced during render。 如何清除警告?[Vue警告]:属性或方法“v”未在实例上定义,但在渲染过程中引用

<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>

回答

2

当你传递一个空属性玉,据我所知,是什么解释,以纯HTML,是attribute="attribute"。在你的情况下,实际的HTML是v-focus="v-focus",vue将其解释为使用属性v的表达式,该属性不存在。

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

+0

非常感谢。我尝试过'input(v-focus =“”)' –

+0

它工作吗?如果是这样,你可以接受答案。 –

+0

我在'inserted'函数中打印'binding'参数。 然后我发现: 当我的代码是“输入(v焦点)”,binding.expression是“v焦点”。 当我的代码是'input(v-focus)'时,绑定没有'expression'属性,并且警告消失 –

相关问题