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'屬性,並且警告消失 –