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>
非常感谢。我尝试过'input(v-focus =“”)' –
它工作吗?如果是这样,你可以接受答案。 –
我在'inserted'函数中打印'binding'参数。 然后我发现: 当我的代码是“输入(v焦点)”,binding.expression是“v焦点”。 当我的代码是'input(v-focus)'时,绑定没有'expression'属性,并且警告消失 –