<!DOCTYPE html>
<body>
<div id="app">
<input type="text" v-focus></input>
</div>
<script src="https://unpkg.com/vue@next"></script>
<script>
const app = Vue.createApp({
data() {
return {
}
}
})
app.mount('#app')
</script>
</body>
</html>
正确的
<!DOCTYPE html>
<body>
<div id="app">
<input v-focus>
</div>
<script src="https://unpkg.com/vue@next"></script>
<script>
const app = Vue.createApp({
});
app.directive('focus', {
mounted(el) {
el.focus()
}
})
app.mount('#app')
</script>
</body>
</html>
什么时候没有数据data
什么时候用directive